from __future__ import annotations

from pydantic import BaseModel, Field


class AgentModelPreset(BaseModel):
    """Mẫu model định sẵn cho Superadmin lựa chọn."""

    id: str
    provider: str
    name: str
    tag: str = "Cloud"


class AgentModelConfigItem(BaseModel):
    """Cấu hình chi tiết Model & Provider cho một AI Agent."""

    agent_code: str
    display_name: str
    role_title: str
    avatar_icon: str = "🤖"
    model_name: str = "gemini-3.8-flash"
    provider: str = "antigravity_sdk"
    temperature: float = 0.20
    max_tokens: int = 4096
    system_prompt_custom: str | None = None
    is_active: bool = True
    updated_at: str | None = None
    is_stealth_promo: bool = False
    stealth_expires_at: str | None = None
    fallback_model_name: str = "gemini-3.8-flash"
    fallback_provider: str = "antigravity_sdk"
    days_until_expiration: int | None = None
    is_expired: bool = False
    available_presets: list[AgentModelPreset] = []


class AgentModelListResponse(BaseModel):
    """Danh sách cấu hình Model & Provider của toàn bộ AI Workforce."""

    agents: list[AgentModelConfigItem]
    default_model: str = "gemini-3.8-flash"
    default_provider: str = "antigravity_sdk"


class UpdateAgentModelRequest(BaseModel):
    """Yêu cầu cập nhật cấu hình Model cho AI Agent."""

    model_name: str = Field(
        ...,
        description="ID model trên OpenRouter/LMStudio/Gemini, ví dụ: stealth/ox-alpha",
    )
    provider: str = Field(
        "openrouter",
        description="Tên provider: openrouter, lmstudio, gemini, openai_compatible",
    )
    temperature: float = Field(0.20, description="Độ sáng tạo / suy luận (0.0 - 1.0)")
    max_tokens: int = Field(2048, description="Giới hạn tokens sinh ra tối đa")
    system_prompt_custom: str | None = Field(
        None, description="Chỉ đạo bổ sung đặc biệt từ Superadmin"
    )
    is_stealth_promo: bool | None = Field(
        None,
        description="Đánh dấu mô hình dùng thử miễn phí có thời hạn (Stealth Promo)",
    )
    stealth_expires_at: str | None = Field(
        None, description="Mốc thời gian hết hạn ưu đãi (ISO format hoặc YYYY-MM-DD)"
    )
    fallback_model_name: str | None = Field(
        None, description="Mô hình dự phòng để tự động chuyển về khi hết hạn Stealth"
    )
    fallback_provider: str | None = Field(
        None, description="Nhà cung cấp của mô hình dự phòng (openrouter, lmstudio)"
    )
