<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Tests\Entity;

use Ferienpass\CoreBundle\Entity\DbafsMedia;
use Ferienpass\CoreBundle\Entity\User;
use PHPUnit\Framework\TestCase;

final class DbafsMediaTest extends TestCase
{
    public function testConstructInitializesCreatedAt(): void
    {
        $media = new DbafsMedia();

        self::assertInstanceOf(\DateTimeInterface::class, $media->getCreatedAt());
    }

    public function testGetUuidNullByDefault(): void
    {
        $media = new DbafsMedia();

        self::assertNull($media->getUuid());
    }

    public function testGetOffersInitiallyEmpty(): void
    {
        $media = new DbafsMedia();

        self::assertCount(0, $media->getOffers());
    }

    public function testSetCreatedAt(): void
    {
        $media = new DbafsMedia();
        $dt = new \DateTimeImmutable('2024-01-01');
        $media->setCreatedAt($dt);

        self::assertSame($dt, $media->getCreatedAt());
    }

    public function testGetUploadedByNullByDefault(): void
    {
        $media = new DbafsMedia();

        self::assertNull($media->getUploadedBy());
    }

    public function testSetUploadedBy(): void
    {
        $media = new DbafsMedia();
        $user = new User();
        $media->setUploadedBy($user);

        self::assertSame($user, $media->getUploadedBy());
    }

    public function testSetLastModified(): void
    {
        $media = new DbafsMedia();
        $media->setLastModified(1700000000);

        self::assertInstanceOf(\DateTimeInterface::class, $media->getLastModified());
    }

    public function testGetImportantPartReturnsArray(): void
    {
        $media = new DbafsMedia();

        $part = $media->getImportantPart();
        self::assertIsArray($part);
        self::assertArrayHasKey('x', $part);
        self::assertArrayHasKey('y', $part);
    }

    public function testSetImportantPart(): void
    {
        $media = new DbafsMedia();
        $media->setImportantPart(['x' => 0.5, 'y' => 0.5, 'width' => 0.5, 'height' => 0.5]);

        $part = $media->getImportantPart();
        self::assertSame(0.5, $part['x']);
    }

    public function testGetAltNullByDefault(): void
    {
        $media = new DbafsMedia();

        self::assertNull($media->getAlt());
    }

    public function testSetAlt(): void
    {
        $media = new DbafsMedia();
        $media->setAlt('My alt text');

        self::assertSame('My alt text', $media->getAlt());
    }

    public function testGetCreatorNullByDefault(): void
    {
        $media = new DbafsMedia();

        self::assertNull($media->getCreator());
    }

    public function testSetCreator(): void
    {
        $media = new DbafsMedia();
        $media->setCreator('John Doe');

        self::assertSame('John Doe', $media->getCreator());
    }
}
