<?php

namespace Tests\Unit\Event;

use App\Domains\Catalog\Models\Variant;
use App\Domains\Event\Models\EventDate;
use App\Domains\Tenant\Models\Tenant;
use App\Domains\Ticket\Models\ValidityTime;
use Tests\TestCase;

class EventModelsTest extends TestCase
{
    public function test_event_date_maps_schedule_and_variants(): void
    {
        $eventDate = new EventDate;
        $eventDate->setRawAttributes([
            'tenant_code' => 'acme',
            'validity_time_id' => '12',
            'date' => '2026-10-09',
            'time_start' => '09:00:00',
            'time_end' => '18:30:00',
        ]);

        $this->assertFalse($eventDate->usesTimestamps());
        $this->assertSame('acme', $eventDate->tenant_code);
        $this->assertSame(12, $eventDate->validity_time_id);
        $this->assertSame('2026-10-09 09:00:00', $eventDate->startsAt()->format('Y-m-d H:i:s'));
        $this->assertSame('2026-10-09 18:30:00', $eventDate->endsAt()->format('Y-m-d H:i:s'));
        $this->assertInstanceOf(Tenant::class, $eventDate->tenant()->getRelated());
        $this->assertInstanceOf(ValidityTime::class, $eventDate->validityTime()->getRelated());
        $this->assertInstanceOf(EventDate::class, (new ValidityTime)->eventDate()->getRelated());
        $this->assertInstanceOf(Variant::class, $eventDate->variants()->getRelated());
    }

    public function test_tenant_has_many_event_dates(): void
    {
        $tenant = new Tenant;

        $this->assertInstanceOf(EventDate::class, $tenant->eventDates()->getRelated());
    }
}
