"""Pydantic schemas for standalone AI assistant chat."""
from typing import Optional, Any
from uuid import UUID
from datetime import datetime
from pydantic import BaseModel, Field

from app.schemas.copilot import SuggestedFlow


class ChatCreateRequest(BaseModel):
    """Empty body — creates a new blank conversation."""
    pass


class ChatMessageRequest(BaseModel):
    message: str = Field(..., min_length=1, max_length=8000)


class ChatMessageResponse(BaseModel):
    content: str
    suggested_flows: list[SuggestedFlow] = []


class ChatListResponse(BaseModel):
    id: UUID
    title: str
    message_count: int
    pinned: bool
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}


class ChatDetailResponse(BaseModel):
    id: UUID
    title: str
    messages: list[dict[str, Any]]
    message_count: int
    pinned: bool
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}


class ChatUpdateRequest(BaseModel):
    title: Optional[str] = Field(None, min_length=1, max_length=255)
    pinned: Optional[bool] = None


class RetentionSettingsResponse(BaseModel):
    chat_retention_days: Optional[int]
    chat_retention_max_count: Optional[int]


class RetentionSettingsUpdate(BaseModel):
    chat_retention_days: Optional[int] = Field(None, ge=1, le=365)
    chat_retention_max_count: Optional[int] = Field(None, ge=10, le=10000)
