"""Tests for the REC-180 axis schema additions to render_schema."""
from __future__ import annotations

import pytest

from recoil.pipeline._lib.render_schema import (
    AxisKind,
    CreativeEpisodeOutput,
    CutRelation,
    EpisodePlan,
    SpatialData,
)


def test_spatial_defaults():
    sd = SpatialData()
    assert sd.camera_side == "A"
    assert sd.screen_direction.value == "center"
    assert sd.axis_segment_id == 0
    assert sd.cut_relation == CutRelation.SCENE_OPEN
    assert sd.axis_transition_reason is None


def test_bad_axis_kind_raises():
    # plain str-Enum (NOT lenient): a bad kind must raise, not coerce to the first member
    with pytest.raises(ValueError):
        AxisKind("bogus")


def test_creative_output_axis_plans_string_key_coercion():
    ceo = CreativeEpisodeOutput.model_validate({
        "episode_id": "EP001", "total_shots": 1,
        "shots": [{"shot_index": 1, "prompt_skeleton": {
            "subject_line": "a", "environment_line": "b", "action_line": "c",
            "motion_line": "d e", "emotion_line": "f"},
            "shot_type": "CU", "target_editorial_duration_s": 4}],
        "axis_plans": {"1": {"initial_anchor": {"kind": "motion", "reference_direction": "left-to-right"}}},
    })
    assert 1 in ceo.axis_plans  # JSON string key -> int


def test_both_json_schemas_carry_axis_plans():
    assert "axis_plans" in CreativeEpisodeOutput.model_json_schema()["properties"]
    assert "axis_plans" in EpisodePlan.model_json_schema()["properties"]
