"""Local file upload endpoint."""

from typing import Annotated

from fastapi import APIRouter, File, UploadFile

from app.api.deps import CurrentUser, UploadServiceDep
from app.api.schemas.upload import UploadResponse

router = APIRouter(prefix="/upload", tags=["upload"])


@router.post("", response_model=UploadResponse)
async def upload_file(
    file: Annotated[UploadFile, File()],
    current_user: CurrentUser,
    service: UploadServiceDep,
) -> UploadResponse:
    result = await service.handle_upload(upload=file, user=current_user)
    return UploadResponse(
        track_id=result.track_id,
        title=result.title,
        already_exists=result.already_exists,
    )
