import uuid
from datetime import datetime
from pydantic import BaseModel


class TenantCreate(BaseModel):
    name: str
    slug: str
    is_active: bool = True


class TenantUpdate(BaseModel):
    name: str | None = None
    slug: str | None = None
    is_active: bool | None = None


class TenantOut(BaseModel):
    id: uuid.UUID
    name: str
    slug: str
    is_active: bool
    user_count: int | None = None
    created_at: datetime

    model_config = {"from_attributes": True}


class TenantAIConfigUpdate(BaseModel):
    ai_enabled: bool = False
    ai_endpoint: str | None = None
    ai_deployment: str = "gpt-4o"
    ai_api_version: str = "2024-02-01"
    ai_api_key: str | None = None     # optional — don't require re-entry
    ai_max_tokens: int = 500
    ai_temperature: float = 0.1
    ai_validation_prompt: str | None = None


class TenantAIConfigOut(BaseModel):
    ai_enabled: bool
    ai_endpoint: str | None
    ai_deployment: str
    ai_api_version: str
    has_api_key: bool              # True if ai_api_key is set — never return the key itself
    ai_max_tokens: int
    ai_temperature: float
    ai_validation_prompt: str | None
