"""Prompts for LLM-based metadata extraction from government documents."""

from app.core.graph_schema_loader import get_schema

# ---------------------------------------------------------------------------
# System prompt
# ---------------------------------------------------------------------------

SYSTEM_PROMPT = """\
你是政务公文元数据提取专家。从用户提供的公文内容中，准确识别并提取结构化字段，\
以 JSON 对象返回，不含任何解释文字。"""

# ---------------------------------------------------------------------------
# User prompt  (use .format(content=...) to fill in the document text)
# ---------------------------------------------------------------------------

_USER_PROMPT_TEMPLATE = """\
请从以下政务公文内容中提取关键元数据。

公文内容（截取前 2000 字）：
---
{content}
---

请返回如下 JSON 对象，字段缺失时返回空字符串或空列表，日期统一为 YYYY-MM-DD 格式：
  "document_scene_type": "standard_service_guide 或 other，仅当文档明显属于标准办事指南时返回 standard_service_guide",

{{{{
  "title":        "文件完整标题，如「关于印发××计划的通知」",
  "doc_number":   "完整文号，如「国办发〔2024〕1号」或「粤府〔2024〕X号」",
  "issuing_org":  "发文机关全称，如「国务院办公厅」",
  "doc_type":     "公文文种，仅限：{doc_types}",
  "publish_date": "发文日期，YYYY-MM-DD，无法确定则返回空字符串",
  "signer":       "签发人姓名，如「李强」，无则返回空字符串",
  "subject_words": ["主题词1", "主题词2"]
}}}}"""


def build_user_prompt(content: str) -> str:
    """Build the metadata extraction user prompt with dynamic doc_types."""
    schema = get_schema()
    doc_types_str = "/".join(schema.doc_types) if schema.doc_types else "通知/决定/通报/报告/请示/批复/函/纪要/意见/公告/其他"
    return _USER_PROMPT_TEMPLATE.format(doc_types=doc_types_str, content=content)
