<?php

declare(strict_types=1);

namespace Ferienpass\CoreBundle\Tests\Entity;

use Ferienpass\CoreBundle\Entity\Offer\OfferInterface;
use Ferienpass\CoreBundle\Entity\OfferDate;
use PHPUnit\Framework\TestCase;

final class OfferDateTest extends TestCase
{
    public function testGetOfferReturnsConstructorArgument(): void
    {
        $offer = $this->createStub(OfferInterface::class);
        $date = new OfferDate($offer);

        self::assertSame($offer, $date->getOffer());
    }

    public function testToHumanReadableReturnsEmptyWhenNoBegin(): void
    {
        $offer = $this->createStub(OfferInterface::class);
        $date = new OfferDate($offer);

        self::assertSame('', $date->toHumanReadable());
    }

    public function testToHumanReadableReturnsEmptyWhenNoEnd(): void
    {
        $offer = $this->createStub(OfferInterface::class);
        $date = new OfferDate($offer);
        $date->setBegin(new \DateTime('2024-06-15 10:00:00'));

        self::assertSame('', $date->toHumanReadable());
    }

    public function testToHumanReadableSameDayFormat(): void
    {
        $offer = $this->createStub(OfferInterface::class);
        $date = new OfferDate($offer);
        $date->setBegin(new \DateTime('2024-06-15 10:00:00', new \DateTimeZone('Europe/Berlin')));
        $date->setEnd(new \DateTime('2024-06-15 12:00:00', new \DateTimeZone('Europe/Berlin')));

        self::assertSame('15.06.2024 10:00 - 12:00', $date->toHumanReadable());
    }

    public function testToHumanReadableMultiDayFormat(): void
    {
        $offer = $this->createStub(OfferInterface::class);
        $date = new OfferDate($offer);
        $date->setBegin(new \DateTime('2024-06-15 10:00:00', new \DateTimeZone('Europe/Berlin')));
        $date->setEnd(new \DateTime('2024-06-16 12:00:00', new \DateTimeZone('Europe/Berlin')));

        self::assertSame('15.06. 10:00 - 16.06.2024 12:00', $date->toHumanReadable());
    }
}
