"""优化建议 Schema"""
import uuid
from datetime import datetime

from pydantic import BaseModel, Field


class SuggestionBase(BaseModel):
    """建议基础Schema"""
    type: str = Field(
        ...,
        description="建议类型: content_optimization/platform_targeting/competitor_gap/query_expansion/citation_improvement",
    )
    priority: str = Field(
        default="medium",
        description="优先级: high/medium/low",
    )
    title: str = Field(..., description="建议标题")
    description: str = Field(..., description="详细描述")
    action: str | None = Field(None, description="具体操作步骤")
    expected_impact: str | None = Field(None, description="预期效果")
    difficulty: str = Field(
        default="medium",
        description="难度: easy/medium/hard",
    )


class SuggestionCreate(SuggestionBase):
    """创建建议Schema"""
    pass


class SuggestionResponse(SuggestionBase):
    """建议响应Schema"""
    id: uuid.UUID = Field(..., description="建议ID")
    brand_id: uuid.UUID = Field(..., description="品牌ID")
    status: str = Field(default="pending", description="状态: pending/in_progress/completed/dismissed")
    generated_at: datetime = Field(..., description="生成时间")
    updated_at: datetime = Field(..., description="更新时间")
    batch_id: uuid.UUID = Field(..., description="生成批次ID")
    source: str = Field(default="rule", description="生成来源: rule/llm")

    class Config:
        from_attributes = True


class SuggestionListResponse(BaseModel):
    """建议列表响应"""
    suggestions: list[SuggestionResponse] = Field(default_factory=list)
    total: int = Field(..., description="总数")


class SuggestionUpdateStatus(BaseModel):
    """更新建议状态"""
    status: str = Field(
        ...,
        description="新状态: pending/in_progress/completed/dismissed",
    )


class SuggestionHistoryItem(BaseModel):
    """建议历史条目"""
    batch_id: uuid.UUID = Field(..., description="批次ID")
    generated_at: datetime = Field(..., description="生成时间")
    source: str = Field(..., description="生成来源: rule/llm")
    suggestion_count: int = Field(..., description="建议数量")
    suggestions: list[SuggestionResponse] = Field(default_factory=list)


class SuggestionHistoryResponse(BaseModel):
    """建议历史响应"""
    history: list[SuggestionHistoryItem] = Field(default_factory=list)
    total: int = Field(..., description="历史批次总数")
