<?php

namespace Tests\Feature\Tenant;

use App\Domains\Tenant\Services\WebsiteTypeService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;

class WebsiteTypeServiceTest extends TestCase
{
    use RefreshDatabase;

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

        $websiteType = app(WebsiteTypeService::class)->create([
            'codigo' => 'marketplace',
            'nombre' => 'Marketplace',
            'dominio' => 'marketplace.test',
            'primary_color' => '#111111',
            'secondary_color' => '#222222',
            'danger_color' => '#ff0000',
            'success_color' => '#00aa55',
            'warning_color' => '#ffaa00',
            'body_color' => '#666666',
            'darker_body_color' => '#333333',
            'surface_color' => '#ffffff',
            'background_color' => '#f8f8f8',
            'border_color' => '#dddddd',
            'login_header_footer_color' => '#333333',
            'site_logo' => UploadedFile::fake()->image('site-logo.png'),
        ]);

        $siteLogo = $websiteType->siteLogo()->firstOrFail();

        $this->assertSame('marketplace', $websiteType->codigo);
        $this->assertSame($siteLogo->id, $websiteType->site_logo);
        $this->assertStringStartsWith('website-types/', $siteLogo->path);
        Storage::disk('s3')->assertExists($siteLogo->path);
        $this->assertDatabaseHas('website_type', [
            'codigo' => 'marketplace',
            'dominio' => 'marketplace.test',
            'warning_color' => '#ffaa00',
            'body_color' => '#666666',
            'darker_body_color' => '#333333',
            'surface_color' => '#ffffff',
            'background_color' => '#f8f8f8',
            'border_color' => '#dddddd',
            'login_header_footer_color' => '#333333',
            'site_logo' => $siteLogo->id,
        ]);
    }
}
