<?php

declare(strict_types=1);

use App\Framework\Config\AppConfig;
use App\Framework\DateTime\ClockInitializer;
use App\Framework\DateTime\SystemClock;
use App\Framework\DateTime\SystemTimer;
use App\Framework\DateTime\Timezone;

beforeEach(function () {
    $this->config = new AppConfig(
        timezone: Timezone::UTC
    );
    $this->initializer = new ClockInitializer($this->config);
});

test('default initialization creates system clock with UTC', function () {
    $clock = ($this->initializer)();

    expect($clock)->toBeInstanceOf(SystemClock::class)
        ->and($clock->now()->getTimezone()->getName())->toBe('UTC');
});

test('custom timezone in config is respected', function () {
    $config = new AppConfig(
        timezone: Timezone::EuropeBerlin
    );
    $initializer = new ClockInitializer($config);
    $clock = $initializer();

    expect($clock)->toBeInstanceOf(SystemClock::class)
        ->and($clock->now()->getTimezone()->getName())->toBe('Europe/Berlin');
});

test('timer initialization works', function () {
    $timer = $this->initializer->initTimer();

    expect($timer)->toBeInstanceOf(SystemTimer::class);
});
