# ============================================================
# src/accountable_record/stage_020_contract/model.py
# ============================================================
"""Contract-context model for Accountable Record stage 020.

WHY:
    Stage 010 establishes repository identity. Stage 020 establishes the
    repository's contract context: either the repository defines the contract
    authority, or it consumes a contract from another repository.

OBS:
    The schema-valid [contract] table differs by repository class. Contract
    repositories declare authority fields. Implementation repositories declare
    the contract they consume. This model records both possibilities without
    requiring fields that are invalid for one class or the other.
"""

from dataclasses import dataclass
from pathlib import Path

__all__ = ["ContractContext", "ContractDeclaration"]


@dataclass(frozen=True)
class ContractDeclaration:
    """Manifest-declared contract context.

    Attributes:
        source_path: Manifest file path the declaration was read from.
        repo_class: Manifest [repo].class used to interpret the declaration.
        consumes_contract_from: Contract reference consumed by implementation
            or downstream repositories.
        contract_version: Contract version declared by contract authority repos.
        contract_role: Role declared by contract authority repos.
        contract_authority: Authority reference declared by contract repos.
        exports_verified_contract: Whether the contract repo exports a verified
            contract.
    """

    source_path: Path
    repo_class: str
    consumes_contract_from: str | None = None
    contract_version: str | None = None
    contract_role: str | None = None
    contract_authority: str | None = None
    exports_verified_contract: bool | None = None


@dataclass(frozen=True)
class ContractContext:
    """Resolved contract context carried forward by the pipeline."""

    declaration: ContractDeclaration
    identity_version: str | None
    version_aligned: bool
    targets_expected_contract: bool
