"""
Confirm Card Model

确认卡片模型 - Agent推送的用户确认任务

特点：
- 用户可以中途退出后随时确认
- 支持多个选项
- 持久化存储
- Agent可以根据用户选择继续任务
"""
from pydantic import BaseModel, Field
from typing import List, Optional, Dict, Any
from datetime import datetime
from enum import Enum


class ConfirmCardType(str, Enum):
    """确认卡片类型"""
    DIRECTION_DECISION = "direction_decision"  # 创作方向决策
    PLOT_BRANCH = "plot_branch"                # 剧情分支选择
    CHARACTER_ACTION = "character_action"      # 角色行为确认
    CONTENT_APPROVAL = "content_approval"      # 内容审批
    RESOURCE_ALLOCATION = "resource_allocation"  # 资源分配确认
    CUSTOM_QUESTION = "custom_question"        # 自定义问题


class ConfirmCardStatus(str, Enum):
    """确认卡片状态"""
    PENDING = "pending"      # 待确认
    APPROVED = "approved"    # 已批准
    REJECTED = "rejected"    # 已拒绝
    MODIFIED = "modified"    # 已修改建议
    EXPIRED = "expired"      # 已过期


class ConfirmCardOption(BaseModel):
    """确认选项"""
    id: str = Field(..., description="选项ID")
    label: str = Field(..., description="选项标签")
    description: str = Field("", description="选项描述")
    implications: Optional[str] = Field(None, description="选择此选项的影响")


class ConfirmCard(BaseModel):
    """
    确认卡片 - Agent推送的用户确认任务
    """
    # 基础信息
    id: str = Field(..., description="卡片ID")
    project_id: str = Field(..., description="项目ID")
    episode_number: Optional[int] = Field(None, description="相关集数")

    # 卡片类型
    card_type: ConfirmCardType = Field(..., description="确认类型")
    title: str = Field(..., description="确认标题")
    description: str = Field(..., description="详细描述")
    context_data: Optional[str] = Field(None, description="上下文信息（长文本）")

    # 确认选项
    options: List[ConfirmCardOption] = Field(default_factory=list, description="可选选项")
    allow_custom_response: bool = Field(False, description="是否允许自定义回复")

    # 用户响应
    status: ConfirmCardStatus = Field(default=ConfirmCardStatus.PENDING, description="状态")
    selected_option_id: Optional[str] = Field(None, description="选择的选项ID")
    custom_response: Optional[str] = Field(None, description="自定义回复内容")
    user_notes: Optional[str] = Field(None, description="用户备注")

    # 时间戳
    created_at: datetime = Field(default_factory=datetime.now, description="创建时间")
    expires_at: Optional[datetime] = Field(None, description="过期时间（可选）")
    confirmed_at: Optional[datetime] = Field(None, description="确认时间")

    # 元数据
    metadata: Dict[str, Any] = Field(default_factory=dict, description="附加信息")

    class Config:
        use_enum_values = False
