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

from pydantic import BaseModel, Field


class BrandBase(BaseModel):
    """Base schema for Brand."""
    name: str = Field(..., min_length=2, max_length=50, description="Brand name")
    aliases: list[str] = Field(default=[], description="Brand aliases")
    website: Optional[str] = Field(None, max_length=500, description="Brand website URL")
    industry: Optional[str] = Field(None, max_length=50, description="Industry")
    platforms: list[str] = Field(
        default=["wenxin", "kimi"],
        description="AI platforms to monitor"
    )
    frequency: str = Field(
        default="weekly",
        description="Query frequency: daily, weekly, or monthly"
    )


class BrandCreate(BrandBase):
    """Schema for creating a brand."""
    pass


class BrandUpdate(BaseModel):
    """Schema for updating a brand."""
    aliases: Optional[list[str]] = None
    website: Optional[str] = None
    industry: Optional[str] = None
    platforms: Optional[list[str]] = None
    frequency: Optional[str] = None
    status: Optional[str] = None


class BrandResponse(BrandBase):
    """Schema for brand response."""
    id: uuid.UUID
    user_id: uuid.UUID
    status: str
    last_queried_at: Optional[datetime] = None
    next_query_at: Optional[datetime] = None
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}


class BrandListResponse(BaseModel):
    """Schema for brand list response."""
    items: list[BrandResponse]
    total: int


class BrandBriefResponse(BaseModel):
    """Schema for brief brand info in lists."""
    id: uuid.UUID
    name: str
    aliases: list[str]
    platforms: list[str]
    frequency: str
    status: str
    last_queried_at: Optional[datetime] = None
    next_query_at: Optional[datetime] = None

    model_config = {"from_attributes": True}
