import uuid
from datetime import datetime
from pydantic import BaseModel
from app.domains.media.models import MediaAssetType


class MediaAssetOut(BaseModel):
    id: uuid.UUID
    tenant_id: uuid.UUID | None
    product_id: uuid.UUID | None
    cad_file_id: uuid.UUID | None
    order_line_id: uuid.UUID | None
    workflow_run_id: uuid.UUID | None
    asset_type: MediaAssetType
    storage_key: str
    file_size_bytes: int | None
    mime_type: str | None
    width: int | None
    height: int | None
    duration_s: float | None
    render_config: dict | None
    is_archived: bool
    created_at: datetime
    download_url: str | None = None
    thumbnail_url: str | None = None

    model_config = {"from_attributes": True}


class MediaAssetBrowseItem(BaseModel):
    """Enriched asset item for the media browser endpoint."""
    id: uuid.UUID
    asset_type: MediaAssetType
    file_path: str
    file_size_bytes: int | None
    mime_type: str | None
    created_at: datetime
    order_line_id: uuid.UUID | None
    product_id: uuid.UUID | None
    product_name: str | None
    product_pim_id: str | None
    category_key: str | None
    render_status: str | None
    # Extended product metadata fields
    product_ebene1: str | None = None
    product_ebene2: str | None = None
    product_baureihe: str | None = None
    product_produkt_baureihe: str | None = None
    product_lagertyp: str | None = None
    product_name_cad_modell: str | None = None
    download_url: str | None = None
    thumbnail_url: str | None = None

    model_config = {"from_attributes": True}


class MediaAssetBrowseResponse(BaseModel):
    items: list[MediaAssetBrowseItem]
    total: int
    page: int
    page_size: int
    pages: int
