"""
应用更新 Schema
===============

Tauri updater 插件所需的请求/响应模型。
"""

from datetime import datetime
from typing import Optional

from pydantic import BaseModel, Field


class PackageInfo(BaseModel):
    """包信息"""

    platform: str
    architecture: str
    filename: str
    file_url: str
    file_size: int
    signature: str


class ReleaseCreate(BaseModel):
    """创建版本发布请求"""

    version: str = Field(..., description="版本号（语义化版本）", examples=["1.6.0"])
    notes: str = Field(default="", description="更新说明（支持换行）")
    mandatory: bool = Field(default=False, description="是否强制更新")
    packages: list[PackageInfo]


class ReleaseResponse(BaseModel):
    """版本发布响应"""

    id: int
    version: str
    release_date: datetime
    notes: str
    mandatory: bool
    created_at: datetime
    packages: list[PackageInfo]


class ReleaseListItem(BaseModel):
    """版本列表项"""

    id: int
    version: str
    release_date: datetime
    notes: str
    mandatory: bool
    package_count: int


# ------------------------------------------------------------------
# Tauri updater 插件所需的 JSON 格式
# ------------------------------------------------------------------

class TauriPlatformInfo(BaseModel):
    """Tauri updater 单平台信息"""

    url: str = Field(..., description="安装包下载地址")
    signature: str = Field(..., description="Ed25519 签名内容（.sig 文件全文）")


class TauriUpdateResponse(BaseModel):
    """Tauri updater 检查更新响应

    参考：https://tauri.app/plugin/updater/
    """

    version: str = Field(..., description="新版本号")
    notes: str = Field(default="", description="更新说明")
    pub_date: Optional[str] = Field(default=None, description="发布时间（RFC 3339）")
    mandatory: bool = Field(default=False, description="是否强制更新（自定义扩展字段）")
    platforms: dict[str, TauriPlatformInfo] = Field(
        ..., description="平台安装包映射，key 格式：OS-ARCH"
    )
