"""T6 创作工具箱 · 7 个生成器输出 schema 的解析/默认值契约测试。

校验 list 字段 default_factory=list（默认空、可解析 mock 产出）。不联网、无 DB。
"""

from __future__ import annotations

from ww_agents import (
    BlurbResult,
    DetailedOutlineResult,
    GlossaryResult,
    GoldenFingerResult,
    NameListResult,
    OpeningResult,
    TitleListResult,
)


def test_title_list_result_parses_and_defaults_empty() -> None:
    assert TitleListResult().titles == []
    parsed = TitleListResult.model_validate(
        {"titles": [{"title": "吞噬星空", "rationale": "升级流爽点抓人"}]}
    )
    assert parsed.titles[0].title == "吞噬星空"


def test_blurb_result_parses_and_defaults_empty() -> None:
    assert BlurbResult().variants == []
    parsed = BlurbResult.model_validate(
        {"variants": [{"text": "废柴逆袭...", "angle": "金手指反差"}]}
    )
    assert parsed.variants[0].angle == "金手指反差"


def test_name_list_result_parses_and_note_optional() -> None:
    assert NameListResult().names == []
    parsed = NameListResult.model_validate({"names": [{"name": "玄阴宗", "kind": "势力"}]})
    assert parsed.names[0].note is None


def test_golden_finger_result_parses_and_defaults_empty() -> None:
    assert GoldenFingerResult().systems == []
    parsed = GoldenFingerResult.model_validate(
        {
            "systems": [
                {
                    "name": "吞噬瞳",
                    "mechanism": "吞噬血脉获能",
                    "growth": "逐级进阶",
                    "limits": "吞噬反噬记忆",
                }
            ]
        }
    )
    assert parsed.systems[0].limits == "吞噬反噬记忆"


def test_glossary_result_parses_and_rules_default_empty() -> None:
    assert GlossaryResult().terms == []
    parsed = GlossaryResult.model_validate(
        {"terms": [{"name": "炼气期", "type": "境界", "definition": "修真初阶"}]}
    )
    assert parsed.terms[0].rules == []


def test_opening_result_parses_and_defaults_empty() -> None:
    assert OpeningResult().variants == []
    parsed = OpeningResult.model_validate({"variants": [{"text": "雷光劈下..."}]})
    assert parsed.variants[0].text == "雷光劈下..."


def test_detailed_outline_result_parses_and_defaults_empty() -> None:
    assert DetailedOutlineResult().scenes == []
    parsed = DetailedOutlineResult.model_validate(
        {
            "scenes": [
                {
                    "idx": 0,
                    "beat": "主角觉醒",
                    "purpose": "立金手指",
                    "conflict": "被族人欺压",
                    "hook": "神秘老者出现",
                }
            ]
        }
    )
    assert parsed.scenes[0].idx == 0
