<?php

declare(strict_types=1);

namespace App\Tests\Util;

use App\Util\LeaveRecapCutoff;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;

/**
 * Cutoff rule: end of ISO week S-1 (previous week's Sunday 23:59:59).
 *
 * @internal
 */
final class LeaveRecapCutoffTest extends TestCase
{
    public function testCutoffIsPreviousWeekSunday(): void
    {
        // Tuesday 2026-04-14 (S16) → Sunday 2026-04-12 23:59:59 (end of S15).
        $cutoff = LeaveRecapCutoff::resolveCutoff(new DateTimeImmutable('2026-04-14'));

        self::assertSame('2026-04-12 23:59:59', $cutoff->format('Y-m-d H:i:s'));
    }

    public function testCutoffFromMondayPointsToPreviousSunday(): void
    {
        // Monday 2026-06-08 → previous Sunday 2026-06-07 23:59:59.
        $cutoff = LeaveRecapCutoff::resolveCutoff(new DateTimeImmutable('2026-06-08'));

        self::assertSame('2026-06-07 23:59:59', $cutoff->format('Y-m-d H:i:s'));
    }

    public function testCutoffFromSundayPointsToPreviousSunday(): void
    {
        // Sunday 2026-06-14 (still in current ISO week) → previous Sunday 2026-06-07.
        $cutoff = LeaveRecapCutoff::resolveCutoff(new DateTimeImmutable('2026-06-14'));

        self::assertSame('2026-06-07 23:59:59', $cutoff->format('Y-m-d H:i:s'));
    }

    public function testCutoffIsAlwaysASundayExactlyOneWeekBeforeCurrentWeek(): void
    {
        // Today 2026-06-11 (Thursday) → end of S-1 = Sunday 2026-06-07.
        $cutoff = LeaveRecapCutoff::resolveCutoff(new DateTimeImmutable('2026-06-11'));

        self::assertSame('Sunday', $cutoff->format('l'));
        self::assertSame('2026-06-07 23:59:59', $cutoff->format('Y-m-d H:i:s'));
    }
}
