"""`SCHEMA_CATALOG`：name → output schema 的唯一真相源（Prompt 外置方案A · 步4）。

Pydantic 类型承载结构化解析与 `isinstance` 校验，无法从文本推导、无法运行时安全构造，
必须留 Python。`SPECS[name].output_schema` 一律从这里派生（单向派生，避免双真相）。
`input_schema` 全 23 个恒为 None（入参为序列化文本），本波不建入参槽（YAGNI）。

`refiner` 是唯一纯文本 writer：`None` 是合法值（无结构化 schema）。
"""

from __future__ import annotations

from typing import Final

from pydantic import BaseModel

from .schemas import (
    BlurbResult,
    BookTeardownResult,
    CharacterGenResult,
    CharacterizationReview,
    ContinuationResult,
    ContinuityReview,
    DeAiResult,
    DetailedOutlineResult,
    ForeshadowReview,
    GlossaryResult,
    GoldenFingerResult,
    IdeaListResult,
    NameListResult,
    OpeningResult,
    OutlineResult,
    PaceReview,
    PolishResult,
    ProjectPlanResult,
    StyleDriftReview,
    StyleFingerprintResult,
    TitleListResult,
    WorldGenResult,
)

# name → output_schema（input 全 None，本波不建入参槽——YAGNI）
SCHEMA_CATALOG: Final[dict[str, type[BaseModel] | None]] = {
    "continuity": ContinuityReview,
    "outliner": OutlineResult,
    "foreshadow": ForeshadowReview,
    "pace": PaceReview,
    "characterization": CharacterizationReview,
    "style_extract": StyleFingerprintResult,
    "style": StyleDriftReview,
    "refiner": None,  # 唯一纯文本 writer，None 是合法值
    "worldbuilder": WorldGenResult,
    "character-gen": CharacterGenResult,
    "brainstorm": IdeaListResult,
    "book-title": TitleListResult,
    "blurb": BlurbResult,
    "name": NameListResult,
    "golden-finger": GoldenFingerResult,
    "glossary": GlossaryResult,
    "opening": OpeningResult,
    "fine-outline": DetailedOutlineResult,
    "continue": ContinuationResult,
    "expand": PolishResult,
    "de-ai": DeAiResult,
    "teardown": BookTeardownResult,
    "project-plan": ProjectPlanResult,
}


def output_schema_for(name: str) -> type[BaseModel] | None:
    """name → output schema（精确字符串相等命中；未知 name → KeyError）。"""
    return SCHEMA_CATALOG[name]
