"""Track request/response schemas."""

import datetime as dt
import uuid

from pydantic import BaseModel


class TrackOut(BaseModel):
    id: uuid.UUID
    title: str
    artist_id: uuid.UUID
    artist_name: str
    album_id: uuid.UUID | None
    album_title: str | None
    duration_seconds: int | None
    file_format: str
    file_size: int
    genre: str | None
    year: int | None
    track_number: int | None
    metadata_status: str
    metadata_error: str | None
    enriched_at: dt.datetime | None
    source: str
    has_cover: bool
    created_at: dt.datetime


class TrackUpdate(BaseModel):
    title: str | None = None
    genre: str | None = None
    year: int | None = None


class MetadataMatch(BaseModel):
    """One AcoustID candidate for the metadata editor's match picker (§A7)."""

    acoustid: str
    score: float
    recording_mbid: str | None
    release_group_mbid: str | None
    title: str | None
    artist: str | None
    album: str | None
    year: int | None


class MetadataMatchesOut(BaseModel):
    items: list[MetadataMatch]


class MetadataApply(BaseModel):
    """Manual edits / accepted match applied via ``PUT /tracks/{id}/metadata``.

    Sets ``metadata_status = manual`` (never overwritten by auto-enrichment)."""

    title: str | None = None
    artist_name: str | None = None
    album_title: str | None = None
    year: int | None = None
    genre: str | None = None
    track_number: int | None = None
