<?php

namespace Tests\Feature\Seeders;

use App\Domains\Tenant\Models\Tenant;
use Database\Seeders\SocialMediaSeeder;
use Database\Seeders\TenantSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;

class TenantSeederTest extends TestCase
{
    use RefreshDatabase;

    public function test_it_loads_the_sonder_main_carousel_images_in_order(): void
    {
        Storage::fake('s3');

        $this->seed([
            SocialMediaSeeder::class,
            TenantSeeder::class,
        ]);

        $tenant = Tenant::query()->where('codigo', 'sonder')->firstOrFail();
        $images = $tenant->mainCarouselImages()->get();

        $this->assertSame([
            '01-urban-team.png',
            '02-running-shoes.png',
            '03-streetwear.png',
            '04-football-training.png',
            '05-activewear-essentials.png',
            '06-city-runners.png',
        ], $images->pluck('filename')->all());
        $this->assertSame([0, 1, 2, 3, 4, 5], $images->pluck('pivot.orden')->all());

        foreach ($images as $image) {
            Storage::disk('s3')->assertExists($image->path);
        }
    }

    public function test_it_assigns_social_media_to_both_tenants_in_order(): void
    {
        Storage::fake('s3');

        $this->seed([
            SocialMediaSeeder::class,
            TenantSeeder::class,
        ]);

        $expectedCodes = ['instagram', 'facebook', 'linkedin', 'whatsapp'];
        $expectedUrls = [
            'https://www.instagram.com/sonderargentina/',
            'https://www.facebook.com/SonderArgentina/',
            'https://www.linkedin.com/company/35664983/',
            'https://wa.me/5493412602222',
        ];

        foreach (['sonder', 'fiesta_futbol_infantil'] as $tenantCode) {
            $socialMedia = Tenant::query()
                ->where('codigo', $tenantCode)
                ->firstOrFail()
                ->socialMedia()
                ->get();

            $this->assertSame($expectedCodes, $socialMedia->pluck('code')->all());
            $this->assertSame($expectedUrls, $socialMedia->pluck('pivot.url')->all());
            $this->assertSame([0, 1, 2, 3], $socialMedia->pluck('pivot.orden')->all());
        }
    }
}
