"""C13 FlightHeader / FlightFooter dataclasses (AZ-292).

The header is the first record of segment 0; the footer is the last
record before clean shutdown. Together they make a per-flight FDR
directory self-describing.
"""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any
from uuid import UUID

__all__ = ["FlightFooter", "FlightHeader"]


@dataclass(frozen=True)
class FlightHeader:
    """First-record-on-disk descriptor for a flight (AZ-292 AC-1).

    ``config_snapshot`` MUST be JSON-safe — the composition root scrubs
    known-secret fields (per AZ-269 redacted-config helper) before
    constructing the header.
    """

    flight_id: UUID
    flight_started_at_iso: str
    flight_started_at_monotonic_ns: int
    config_snapshot: dict[str, Any] = field(default_factory=dict)
    signing_key_rotation_event: dict[str, Any] = field(default_factory=dict)
    manifest_content_hashes: dict[str, str] = field(default_factory=dict)
    build_info: dict[str, Any] = field(default_factory=dict)


@dataclass(frozen=True)
class FlightFooter:
    """Last-record-on-disk descriptor for a flight (AZ-292 AC-2).

    The four counters (``records_written``, ``records_dropped_overrun``,
    ``bytes_written``, ``rollover_count``) are the AC-NEW-3 canonical
    audit trail. ``clean_shutdown`` distinguishes a graceful landing
    from a power-loss truncation.
    """

    flight_id: UUID
    flight_ended_at_iso: str
    flight_ended_at_monotonic_ns: int
    records_written: int
    records_dropped_overrun: int
    bytes_written: int
    rollover_count: int
    clean_shutdown: bool
