import uuid
from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field


class CompetitorAnalysisRequest(BaseModel):
    brand_id: uuid.UUID = Field(..., description="品牌ID")
    analysis_types: list[str] | None = Field(
        None,
        description="分析类型列表: citation_gap/content_strategy/platform_coverage/query_overlap/differentiation",
    )
    period_days: int | None = Field(30, description="分析周期天数")


class CompetitorInsightResponse(BaseModel):
    id: uuid.UUID = Field(..., description="洞察ID")
    brand_id: uuid.UUID = Field(..., description="品牌ID")
    competitor_name: str = Field(..., description="竞品名称")
    analysis_type: str = Field(..., description="分析类型")
    insight_data: dict | None = Field(None, description="洞察数据")
    citation_count_brand: int = Field(0, description="品牌引用次数")
    citation_count_competitor: int = Field(0, description="竞品引用次数")
    sentiment_brand: float | None = Field(None, description="品牌情感分数")
    sentiment_competitor: float | None = Field(None, description="竞品情感分数")
    platform_breakdown: dict | None = Field(None, description="平台分布")
    gap_analysis: dict | None = Field(None, description="差距分析")
    opportunity_areas: dict | None = Field(None, description="机会领域")
    recommendations: dict | None = Field(None, description="策略建议")
    confidence: str = Field("medium", description="置信度: high/medium/low")
    period_days: int = Field(30, description="分析周期天数")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="更新时间")

    model_config = {"from_attributes": True}


class CompetitorInsightList(BaseModel):
    items: list[CompetitorInsightResponse] = Field(default_factory=list, description="洞察列表")
    total: int = Field(0, description="总数")


class CompetitorGapSummary(BaseModel):
    brand_name: str = Field(..., description="品牌名称")
    competitor_name: str = Field(..., description="竞品名称")
    gap_dimensions: list[dict] = Field(default_factory=list, description="差距维度列表")
    overall_gap_score: float = Field(0.0, description="综合差距分数(0-100)")
