"""日报结构化入库：数据模型。"""

from __future__ import annotations

from datetime import date, datetime
from typing import Any

from pydantic import BaseModel, Field


class EventRow(BaseModel):
    """一条事件记录，对应 news_event 一行。"""

    section: str  # xwlb | news | cninfo | intl
    rank: int  # 板块内序号（从 1 开始）
    importance: int | None = None
    event_type: str | None = None
    title: str
    summary: str | None = None
    sentiment: str | None = None  # positive | negative | neutral | ''
    source: str | None = None
    url: str | None = None


class ReportData(BaseModel):
    """一份完整日报：news_report 一行 + news_event 多行。"""

    report_date: date
    report_type: str  # finance | intl
    file_name: str = ""  # 源文件名（新生成日报可为空）
    generated_at: datetime
    ai_summary: str | None = None
    stats: dict[str, Any] = Field(default_factory=dict)
    events: list[EventRow] = Field(default_factory=list)
