"""Competitor schemas for request/response validation."""
import uuid
from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field


class CompetitorBase(BaseModel):
    """Base schema for Competitor."""
    name: str = Field(..., min_length=2, max_length=50, description="Competitor name")
    aliases: list[str] = Field(default=[], description="Competitor aliases")


class CompetitorCreate(CompetitorBase):
    """Schema for creating a competitor."""
    pass


class CompetitorUpdate(BaseModel):
    """Schema for updating a competitor."""
    name: Optional[str] = Field(None, min_length=2, max_length=50)
    aliases: Optional[list[str]] = None


class CompetitorResponse(CompetitorBase):
    """Schema for competitor response."""
    id: uuid.UUID
    brand_id: uuid.UUID
    created_at: datetime

    model_config = {"from_attributes": True}


class CompetitorListResponse(BaseModel):
    """Schema for competitor list response."""
    items: list[CompetitorResponse]
    total: int


class CompetitorBriefResponse(BaseModel):
    """Schema for brief competitor info."""
    id: uuid.UUID
    name: str
    aliases: list[str]
    score: Optional[int] = None

    model_config = {"from_attributes": True}


class CompetitorRecommendationItem(BaseModel):
    """Schema for a single competitor recommendation."""
    name: str = Field(..., description="竞品名称")
    reason: str = Field(..., description="推荐理由")
    industry: Optional[str] = Field(None, description="所属行业")


class CompetitorRecommendationResponse(BaseModel):
    """Schema for competitor recommendation response."""
    brand_name: str = Field(..., description="品牌名称")
    industry: Optional[str] = Field(None, description="品牌行业")
    recommendations: list[CompetitorRecommendationItem] = Field(
        default_factory=list, description="推荐竞品列表"
    )
