"""Pydantic schemas for packs API."""
from datetime import datetime
from typing import Literal

from pydantic import BaseModel, Field

PackTier = Literal["starter", "pro", "master"]


class SignLinkRequest(BaseModel):
    """Vercel → backend: 사용자 다운로드 링크 발급 요청."""
    file_path: str = Field(..., description="NAS 절대 경로 — pack_files.file_path 그대로")
    expires_in_seconds: int = Field(default=14400, description="공유 링크 만료 (기본 4시간)")


class SignLinkResponse(BaseModel):
    url: str
    expires_at: datetime


class UploadResponse(BaseModel):
    file_id: str  # uuid
    file_path: str
    filename: str
    size_bytes: int
    min_tier: PackTier
    label: str
    uploaded_at: datetime


class PackFileItem(BaseModel):
    id: str
    min_tier: PackTier
    label: str
    file_path: str
    filename: str
    size_bytes: int
    sort_order: int
    uploaded_at: datetime


class MintTokenRequest(BaseModel):
    """Vercel → backend: admin upload 토큰 발급 요청."""
    tier: PackTier
    label: str = Field(..., max_length=200)
    filename: str = Field(..., max_length=255)
    size_bytes: int = Field(..., gt=0, le=5 * 1024 * 1024 * 1024)


class MintTokenResponse(BaseModel):
    token: str
    expires_at: datetime
    jti: str


class InitUploadResponse(BaseModel):
    """chunked upload 세션 초기화 응답. session_id는 mint-token의 jti와 동일."""
    session_id: str
    chunk_max_size: int
    expected_size: int
    expires_at: datetime


class ChunkUploadResponse(BaseModel):
    written: int
    expected_size: int
