<?php

use App\Services\DashboardService;
use App\Services\NotificationService;
use App\Services\RecurrenceService;
use App\Support\AppClock;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;

/**
 * @internal
 */
final class AppClockTest extends CIUnitTestCase
{
    public function testClockUsesConfiguredApplicationTimezone(): void
    {
        $expected = (new App())->appTimezone;
        $this->assertNotSame('', $expected);
        $this->assertSame($expected, app_timezone());
        $this->assertSame($expected, AppClock::timezone()->getName());
        $this->assertSame($expected, AppClock::now()->getTimezone()->getName());
        $this->assertSame($expected, AppClock::today()->getTimezone()->getName());
        $this->assertSame('00:00:00', AppClock::today()->format('H:i:s'));
        $this->assertSame($expected, AppClock::parse('2026-08-29')->getTimezone()->getName());
        $this->assertSame($expected, date_default_timezone_get());
    }

    public function testDashboardRecurrenceAndNotificationsShareTheClock(): void
    {
        $tz = app_timezone();
        $this->assertSame($tz, (new DashboardService())->today()->getTimezone()->getName());
        $this->assertSame($tz, (new RecurrenceService())->today()->getTimezone()->getName());
        $this->assertSame($tz, (new NotificationService())->now()->getTimezone()->getName());
    }
}
