from __future__ import annotations

from datetime import date, datetime, time, timezone

from checkin_cli.weekly_operations_schedule_host_models_r4 import (
    ScheduledDeliveryReceipt,
    WeeklyOperationsSchedulePolicy,
)
from checkin_cli.weekly_operations_schedule_host_review_r4 import (
    non_response_review_candidate,
)


def test_review_candidate_is_stable_when_reminder_window_closes() -> None:
    # Given: one audited weekly reminder and its closed response window.
    reminder = ScheduledDeliveryReceipt(
        reservation_id="weekly-reminder-1",
        schedule_key="client_001:reminder:2026-08-24",
        customer_key="client_001",
        kind="reminder",
        kst_day=date(2026, 8, 24),
        state="sent_audited",
        body_digest="a" * 64,
        template_digest="b" * 64,
        destination_digest="c" * 64,
        registry_digest="d" * 64,
        config_digest="e" * 64,
    )
    cutoff = datetime(2026, 8, 24, 15, tzinfo=timezone.utc)

    # When: the host projects the review signal twice.
    first = non_response_review_candidate(
        reminder,
        response_window_ends_at=cutoff,
        now=cutoff,
    )
    second = non_response_review_candidate(
        reminder,
        response_window_ends_at=cutoff,
        now=cutoff,
    )

    # Then: the observable correlation identity remains deterministic.
    assert first == second


def test_weekly_schedule_policy_keeps_approved_cutoff() -> None:
    # Given: the fixed weekly customer set.
    customers = frozenset(("client_001",))

    # When: the approved fixed schedule is constructed.
    policy = WeeklyOperationsSchedulePolicy(customers)

    # Then: its reminder and cutoff remain the approved KST values.
    assert (policy.reminder_time, policy.cutoff_time) == (time(20), time(23))
