"""Storage ingest API schemas."""
from __future__ import annotations

from uuid import UUID

from pydantic import BaseModel, Field


class StorageIngestJobResponse(BaseModel):
    job_id: str
    status: str
    poll_url: str
    bucket_name: str
    extract_archive: bool = False
    is_archive: bool = False


class StartIngestUploadSessionRequest(BaseModel):
    filename: str = Field(..., min_length=1, max_length=512)
    size_bytes: int = Field(..., gt=0)
    bucket_name: str = Field(..., min_length=1, max_length=63)
    connection_id: UUID
    object_key: str | None = Field(None, max_length=1024)
    extract_archive: bool = True
    archive_path_mode: str = Field(
        default="preserve_folders",
        description="preserve_folders (default) or flatten (folder-sub-file.png)",
    )


class IngestUploadSessionResponse(BaseModel):
    job_id: str
    status: str
    poll_url: str
    bucket_name: str
    extract_archive: bool = False
    is_archive: bool = False
    chunk_size_bytes: int
    total_parts: int
    expected_size_bytes: int


class IngestUploadPartResponse(BaseModel):
    job_id: str
    part_number: int
    received_bytes: int
    next_part_number: int
    complete: bool = False


class StorageIngestJobStatusResponse(BaseModel):
    job_id: str
    status: str
    bucket_name: str
    original_filename: str
    extract_archive: bool
    is_archive: bool
    archive_path_mode: str = "preserve_folders"
    uploaded_count: int = 0
    total_entries: int | None = None
    skipped_count: int = 0
    expected_size_bytes: int | None = None
    received_bytes: int | None = None
    error: str | None = None
    result: dict | None = None
