"""AI 集成层 Pydantic 模型定义。

覆盖请求/响应体、缓存类型枚举、线索模型、各应用结果模型。
"""

from __future__ import annotations

import enum

from pydantic import BaseModel, Field


# ── 请求/响应 ──


class ChatStreamRequest(BaseModel):
    """SSE 流式对话请求体"""

    message: str
    source_page: str | None = None
    page_context: dict | None = None
    screen_content: str | None = None


class SSEEvent(BaseModel):
    """SSE 事件"""

    type: str  # chunk / done / error
    content: str | None = None
    conversation_id: int | None = None
    tokens_used: int | None = None
    message: str | None = None


# ── 缓存类型枚举 ──


class CacheTypeEnum(str, enum.Enum):
    APP2_FINANCE = "app2_finance"
    APP2A_FINANCE_AREA = "app2a_finance_area"  # 2026-04-23 新增：区域财务洞察（64 组合）
    APP3_CLUE = "app3_clue"
    APP4_ANALYSIS = "app4_analysis"
    APP5_TACTICS = "app5_tactics"
    APP6_NOTE_ANALYSIS = "app6_note_analysis"
    APP7_CUSTOMER_ANALYSIS = "app7_customer_analysis"
    APP8_CLUE_CONSOLIDATED = "app8_clue_consolidated"


# ── 线索相关 ──


class App3CategoryEnum(str, enum.Enum):
    """App3 线索分类（3 个枚举值）"""

    CUSTOMER_BASIC = "客户基础"
    CONSUMPTION_HABIT = "消费习惯"
    PLAY_PREFERENCE = "玩法偏好"


class App6CategoryEnum(str, enum.Enum):
    """App6/8 线索分类（6 个枚举值）"""

    CUSTOMER_BASIC = "客户基础"
    CONSUMPTION_HABIT = "消费习惯"
    PLAY_PREFERENCE = "玩法偏好"
    PROMO_PREFERENCE = "促销偏好"
    SOCIAL_RELATION = "社交关系"
    IMPORTANT_FEEDBACK = "重要反馈"


class ClueItem(BaseModel):
    """单条线索（App3/App6 共用）"""

    category: str
    summary: str
    detail: str
    emoji: str


class ConsolidatedClueItem(BaseModel):
    """整合后线索（App8，含 providers）"""

    category: str
    summary: str
    detail: str
    emoji: str
    providers: str


# ── 各应用结果模型 ──


class App2InsightItem(BaseModel):
    """App2 财务洞察单条"""

    seq: int
    title: str
    body: str


class App2Result(BaseModel):
    """App2 财务洞察结果"""

    insights: list[App2InsightItem]


class App3Result(BaseModel):
    """App3 客户数据维客线索结果"""

    clues: list[ClueItem]


class App4Result(BaseModel):
    """App4 关系分析结果"""

    task_description: str
    action_suggestions: list[str]
    one_line_summary: str


class App5TacticsItem(BaseModel):
    """App5 话术单条"""

    scenario: str
    script: str


class App5Result(BaseModel):
    """App5 话术参考结果"""

    tactics: list[App5TacticsItem]


class App6Result(BaseModel):
    """App6 备注分析结果"""

    score: int = Field(ge=1, le=10)
    clues: list[ClueItem]


class App7StrategyItem(BaseModel):
    """App7 客户分析策略单条"""

    title: str
    content: str


class App7Result(BaseModel):
    """App7 客户分析结果"""

    strategies: list[App7StrategyItem]
    summary: str


class App8Result(BaseModel):
    """App8 维客线索整理结果"""

    clues: list[ConsolidatedClueItem]
