from __future__ import annotations

from fastapi import APIRouter, Depends

from backend.app.api.schemas import CopyRequest, TaskCreateResponse
from backend.app.dependencies import get_copy_task_service
from backend.app.services.copy_task_service import CopyTaskService

router = APIRouter(prefix="/files")


@router.post("/copy", response_model=TaskCreateResponse, status_code=202)
async def copy_file(
    request: CopyRequest,
    service: CopyTaskService = Depends(get_copy_task_service),
) -> TaskCreateResponse:
    if request.sources is not None:
        return service.create_batch_copy_task(
            sources=request.sources,
            destination_base=request.destination_base,
        )
    return service.create_copy_task(source=request.source, destination=request.destination)
