"""平台/服务商 Schema"""

from datetime import datetime
from typing import Optional

from sqlmodel import SQLModel

from app.models.provider import ProviderCategory


class ProviderBase(SQLModel):
    slug: str
    name: str
    name_en: Optional[str] = None
    category: ProviderCategory
    services: Optional[str] = None
    website: Optional[str] = None
    console_url: Optional[str] = None
    sdk_type: Optional[str] = None
    enabled: bool = True
    remark: Optional[str] = None


class ProviderCreate(ProviderBase):
    """创建平台；api_config 为明文 JSON 字符串，服务端加密存储"""

    api_config: Optional[str] = None


class ProviderUpdate(SQLModel):
    slug: Optional[str] = None
    name: Optional[str] = None
    name_en: Optional[str] = None
    category: Optional[ProviderCategory] = None
    services: Optional[str] = None
    website: Optional[str] = None
    console_url: Optional[str] = None
    sdk_type: Optional[str] = None
    enabled: Optional[bool] = None
    remark: Optional[str] = None
    api_config: Optional[str] = None


class ProviderRead(ProviderBase):
    id: int
    created_at: datetime
    last_synced_at: Optional[datetime] = None
    has_api_config: bool = False
