"""Hard gates for final-visual proof artifacts.

A content visual proof must prove the intended production path. Blind T2V and
fallback animatics are allowed only as internal experiments/review artifacts;
they must not advance a candidate toward a full final render.
"""

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum


class VisualProofKind(str, Enum):
    WAN_VIDEO = "wan_video"
    ANIMATIC = "animatic"
    FULL_FINAL = "full_final"
    INTERNAL_TECH_TEST = "internal_tech_test"


@dataclass(frozen=True)
class VisualProofCandidate:
    kind: VisualProofKind
    prompt_only_generation: bool
    has_start_frame: bool
    has_valid_wan_output: bool
    has_end_frame: bool = False
    accepted_scene_proof: bool = False
    accepted_keyframes: bool = False


@dataclass(frozen=True)
class VisualProofPolicyResult:
    allowed: bool
    reasons: tuple[str, ...]


def evaluate_visual_proof_candidate(candidate: VisualProofCandidate) -> VisualProofPolicyResult:
    reasons: list[str] = []

    if candidate.kind != VisualProofKind.INTERNAL_TECH_TEST and candidate.prompt_only_generation:
        reasons.append("prompt_only_generation_blocked")

    if candidate.kind == VisualProofKind.ANIMATIC:
        reasons.append("animatic_not_valid_visual_proof")

    if candidate.kind == VisualProofKind.WAN_VIDEO:
        if not candidate.has_start_frame:
            reasons.append("i2v_requires_start_frame")
        if not candidate.has_valid_wan_output:
            reasons.append("wan_output_required")

    if candidate.kind == VisualProofKind.FULL_FINAL:
        if not candidate.has_valid_wan_output:
            reasons.append("full_final_requires_valid_wan_output")
        if not (candidate.accepted_scene_proof or candidate.accepted_keyframes):
            reasons.append("full_final_requires_accepted_scene_proof_or_keyframes")

    return VisualProofPolicyResult(allowed=not reasons, reasons=tuple(reasons))
