"""VP profile.md section schema — v0.28."""

from __future__ import annotations

REQUIRED_PROFILE_SECTIONS: tuple[str, ...] = (
    "性格与做事",
    "作品与经历",
    "人物故事",
    "对用户的称呼",
)

# Sections enrich may fill (user-facing addressing is edited separately).
ENRICH_PROFILE_SECTIONS: tuple[str, ...] = (
    "性格与做事",
    "作品与经历",
    "人物故事",
)

# Sections distilled in deep-learn (skip addressing).
DEEP_LEARN_PROFILE_SECTIONS: tuple[str, ...] = ENRICH_PROFILE_SECTIONS


class VirtualPersonaValidationError(ValueError):
    """profile.md 或 meta 校验失败。"""


def default_profile_md(label: str) -> str:
    name = str(label or "新角色").strip() or "新角色"
    lines = [f"# {name}", ""]
    for section in REQUIRED_PROFILE_SECTIONS:
        lines.append(f"## {section}")
        lines.append("")
        lines.append("")
    return "\n".join(lines).rstrip() + "\n"


def validate_profile_sections(profile_md: str) -> None:
    """校验 profile.md 含全部必需 ## 章节。"""
    text = str(profile_md or "")
    missing = [sec for sec in REQUIRED_PROFILE_SECTIONS if f"## {sec}" not in text]
    if missing:
        raise VirtualPersonaValidationError(f"missing profile sections: {', '.join(missing)}")
