<?php

namespace Tests\Framework\DateTime;

use App\Framework\DateTime\Clock;
use App\Framework\DateTime\ClockInitializer;
use App\Framework\DateTime\FrozenClock;
use App\Framework\DateTime\SystemClock;

class ClockInitializerTest extends \PHPUnit\Framework\TestCase
{
    public function testDefaultInitialization(): void
    {
        $initializer = new ClockInitializer();
        $clock = $initializer();

        $this->assertInstanceOf(SystemClock::class, $clock);
        $this->assertEquals('UTC', $clock->now()->getTimezone()->getName());
    }

    public function testCustomTimezone(): void
    {
        $initializer = new ClockInitializer('Europe/Berlin');
        $clock = $initializer();

        $this->assertInstanceOf(SystemClock::class, $clock);
        $this->assertEquals('Europe/Berlin', $clock->now()->getTimezone()->getName());
    }

    public function testFrozenClockInitialization(): void
    {
        $initializer = new ClockInitializer(
            useFrozenClock: true,
            frozenTime: '2021-01-01 12:00:00'
        );
        $clock = $initializer();

        $this->assertInstanceOf(FrozenClock::class, $clock);
        $this->assertEquals('2021-01-01 12:00:00', $clock->now()->format('Y-m-d H:i:s'));
    }

    public function testFrozenClockWithCustomTimezone(): void
    {
        $initializer = new ClockInitializer(
            timezone: 'Europe/Berlin',
            useFrozenClock: true,
            frozenTime: '2021-01-01 12:00:00'
        );
        $clock = $initializer();

        $this->assertInstanceOf(FrozenClock::class, $clock);
        $this->assertEquals('Europe/Berlin', $clock->now()->getTimezone()->getName());
    }
}
