<?php

namespace App\Tests\Entity;

use App\Entity\Event;
use App\Entity\User;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\File\File;

class EventTest extends TestCase
{
    public function testNewEventHasNullId(): void
    {
        $event = new Event();
        self::assertNull($event->getId());
    }

    public function testCreatedAtIsSetOnConstruction(): void
    {
        $event = new Event();
        self::assertInstanceOf(\DateTimeImmutable::class, $event->getCreatedAt());
    }

    public function testSetAndGetAccount(): void
    {
        $event = new Event();
        $user = new User();
        $user->setEmail('orga@example.com');
        $user->setFirstName('Test');
        $user->setLastName('Orga');
        $user->setPassword('hashed');

        $result = $event->setAccount($user);

        self::assertSame($user, $event->getAccount());
        self::assertSame($event, $result);
    }

    public function testSetAndGetTitle(): void
    {
        $event = new Event();
        $result = $event->setTitle('Brocante de printemps 2026');

        self::assertSame('Brocante de printemps 2026', $event->getTitle());
        self::assertSame($event, $result);
    }

    public function testSetAndGetStartAt(): void
    {
        $event = new Event();
        $date = new \DateTimeImmutable('2026-06-15 10:00:00');
        $result = $event->setStartAt($date);

        self::assertSame($date, $event->getStartAt());
        self::assertSame($event, $result);
    }

    public function testSetAndGetEndAt(): void
    {
        $event = new Event();
        $date = new \DateTimeImmutable('2026-06-15 18:00:00');
        $result = $event->setEndAt($date);

        self::assertSame($date, $event->getEndAt());
        self::assertSame($event, $result);
    }

    public function testSetAndGetDescription(): void
    {
        $event = new Event();
        $result = $event->setDescription('Grande brocante avec stands et animations.');

        self::assertSame('Grande brocante avec stands et animations.', $event->getDescription());
        self::assertSame($event, $result);
    }

    public function testDescriptionIsNullByDefault(): void
    {
        $event = new Event();
        self::assertNull($event->getDescription());
    }

    public function testSetAndGetAddress(): void
    {
        $event = new Event();
        $result = $event->setAddress('12 avenue de la Republique');

        self::assertSame('12 avenue de la Republique', $event->getAddress());
        self::assertSame($event, $result);
    }

    public function testSetAndGetZipcode(): void
    {
        $event = new Event();
        $result = $event->setZipcode('75011');

        self::assertSame('75011', $event->getZipcode());
        self::assertSame($event, $result);
    }

    public function testSetAndGetCity(): void
    {
        $event = new Event();
        $result = $event->setCity('Paris');

        self::assertSame('Paris', $event->getCity());
        self::assertSame($event, $result);
    }

    public function testSetAndGetEventMainPictureName(): void
    {
        $event = new Event();
        $result = $event->setEventMainPictureName('event-photo.jpg');

        self::assertSame('event-photo.jpg', $event->getEventMainPictureName());
        self::assertSame($event, $result);
    }

    public function testSetEventMainPictureFileUpdatesTimestamp(): void
    {
        $event = new Event();
        self::assertNull($event->getUpdatedAt());

        $file = $this->createMock(File::class);
        $result = $event->setEventMainPictureFile($file);

        self::assertSame($file, $event->getEventMainPictureFile());
        self::assertInstanceOf(\DateTimeImmutable::class, $event->getUpdatedAt());
        self::assertSame($event, $result);
    }

    public function testIsOnlineDefaultFalse(): void
    {
        $event = new Event();
        self::assertFalse($event->isOnline());
    }

    public function testSetAndGetIsOnline(): void
    {
        $event = new Event();
        $result = $event->setIsOnline(true);

        self::assertTrue($event->isOnline());
        self::assertSame($event, $result);
    }

    public function testGetSlug(): void
    {
        $event = new Event();
        $event->setTitle('Brocante de printemps 2026');
        self::assertSame('brocante-de-printemps-2026', $event->getSlug());
    }

    public function testGetSlugEmpty(): void
    {
        $event = new Event();
        self::assertSame('evenement', $event->getSlug());
    }

    public function testIsSecretDefaultFalse(): void
    {
        $event = new Event();
        self::assertFalse($event->isSecret());
    }

    public function testSetAndGetIsSecret(): void
    {
        $event = new Event();
        $result = $event->setIsSecret(true);

        self::assertTrue($event->isSecret());
        self::assertSame($event, $result);
    }

    public function testSetEventMainPictureFileNullDoesNotUpdateTimestamp(): void
    {
        $event = new Event();
        $event->setEventMainPictureFile(null);

        self::assertNull($event->getUpdatedAt());
        self::assertNull($event->getEventMainPictureFile());
    }
}
