"""Todo 5 manifest-bound terminal lineage regression."""

from __future__ import annotations

from datetime import datetime
from pathlib import Path

import anyio

from checkin_cli.customer_schedule import schedule_delivery_ledger
from checkin_cli.weekly_operations_lifecycle import ReminderDependencies, ReminderOutcome, run_due_reminder
from tests._weekly_operations_lifecycle_support import KST, FakeReminderProvider, ProviderMode, fixture_at


def test_known_failure_is_terminal_for_customer_day(tmp_path: Path) -> None:
    """Given a known failure, when replayed, then one lineage and one call remain."""
    # Given
    fixture = fixture_at(tmp_path, datetime(2026, 8, 17, 20, tzinfo=KST))
    provider = FakeReminderProvider(ProviderMode.KNOWN_FAILURE)
    dependencies = ReminderDependencies(provider, lambda: fixture.request.bound_customer)

    # When
    first = anyio.run(run_due_reminder, fixture.request, dependencies)
    replay = anyio.run(run_due_reminder, fixture.request, dependencies)

    # Then
    assert first.outcome is ReminderOutcome.KNOWN_FAILURE
    assert replay.outcome is ReminderOutcome.KNOWN_FAILURE
    assert provider.calls == 1
    assert len({row.reservation_id for row in fixture.request.bound_customer.ledger.receipts()}) == 1
    fixture.close()
