from __future__ import annotations

import uuid
from typing import Optional

from receipts.domains.replay_passport_v2 import PassportLineage, ReplayPassportV2


def build_pa_replay_passport_v2(
    *,
    subject_id: str,
    decision_id: str,
    tileset_id: str,
    tile_hash: str,
    semantic_field_version: Optional[str] = None,
    index_snapshot_hash: Optional[str] = None,
) -> ReplayPassportV2:
    """
    Construct a ReplayPassportV2 with sane defaults for guardian tests.
    """
    passport_id = decision_id or subject_id or f"passport-{uuid.uuid4().hex}"

    return ReplayPassportV2(
        request_id=passport_id,
        passport_id=passport_id,
        vault_id=tileset_id,
        guardian_verdict=None,
        lineage=PassportLineage(),
        metadata={
            "subject_id": subject_id,
            "decision_id": decision_id,
            "tileset_id": tileset_id,
            "tile_hash": tile_hash,
            "semantic_field_version": semantic_field_version,
            "index_snapshot_hash": index_snapshot_hash,
        },
    )

