import uuid
from datetime import datetime

from pydantic import BaseModel, Field


class GeoPlanGenerateRequest(BaseModel):
    brand_id: uuid.UUID = Field(..., description="品牌ID")
    target_score: int | None = Field(75, description="目标评分")


class GeoPlanActionResponse(BaseModel):
    id: uuid.UUID = Field(..., description="行动项ID")
    plan_id: uuid.UUID = Field(..., description="方案ID")
    action_type: str = Field(..., description="行动类型")
    title: str = Field(..., description="行动标题")
    description: str = Field(..., description="详细描述")
    reason: str = Field(..., description="基于诊断数据的原因")
    priority: str = Field(..., description="优先级: high/medium/low")
    status: str = Field(..., description="状态: pending/in_progress/completed/skipped")
    target_keyword: str | None = Field(None, description="预填关键词")
    target_platform: str | None = Field(None, description="预填平台")
    content_style: str | None = Field(None, description="预填风格")
    estimated_impact: str | None = Field(None, description="预期效果")
    difficulty: str = Field(..., description="难度: easy/medium/hard")
    execution_params: dict | None = Field(None, description="一键执行参数")
    sort_order: int = Field(0, description="排序序号")
    completed_at: datetime | None = Field(None, description="完成时间")
    created_at: datetime = Field(..., description="创建时间")

    class Config:
        from_attributes = True


class GeoPlanResponse(BaseModel):
    id: uuid.UUID = Field(..., description="方案ID")
    brand_id: uuid.UUID = Field(..., description="品牌ID")
    title: str = Field(..., description="方案标题")
    status: str = Field(..., description="状态: draft/active/completed/archived")
    diagnosis_score: int = Field(..., description="诊断评分")
    target_score: int = Field(..., description="目标评分")
    estimated_weeks: int = Field(..., description="预计周数")
    plan_data: dict | None = Field(None, description="方案详细数据")
    source: str = Field(..., description="生成来源: rule/llm")
    actions: list[GeoPlanActionResponse] = Field(
        default_factory=list, description="行动项列表"
    )
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="更新时间")

    class Config:
        from_attributes = True


class GeoPlanListResponse(BaseModel):
    plans: list[GeoPlanResponse] = Field(default_factory=list, description="方案列表")
    total: int = Field(..., description="总数")


class GeoPlanActionUpdateStatus(BaseModel):
    status: str = Field(
        ..., description="新状态: pending/in_progress/completed/skipped"
    )


class GeoPlanActionExecuteResponse(BaseModel):
    action_id: uuid.UUID = Field(..., description="行动项ID")
    content_id: str | None = Field(None, description="生成的内容ID")
    message: str = Field(..., description="执行结果消息")
