<?php

declare(strict_types=1);

namespace App\Util;

use DateTimeImmutable;

/**
 * Leave recap cutoff rule: as-of end of ISO week S-1 (Sunday 23:59:59).
 *
 * Example: Tuesday 2026-04-14 (S16) → Sunday 2026-04-12 23:59:59 (end of S15).
 */
final class LeaveRecapCutoff
{
    public static function resolveCutoff(DateTimeImmutable $today): DateTimeImmutable
    {
        $currentWeekMonday = $today->modify('monday this week')->setTime(0, 0);
        $cutoffWeekMonday  = $currentWeekMonday->modify('-7 days');

        return $cutoffWeekMonday->modify('+6 days')->setTime(23, 59, 59);
    }
}
