from __future__ import annotations

from fastapi import APIRouter, Depends, status

from backend.app.api.schemas import TaskDetailResponse, TaskListResponse
from backend.app.dependencies import get_task_service
from backend.app.services.task_service import TaskService

router = APIRouter(prefix="/tasks")


@router.get("", response_model=TaskListResponse)
async def list_tasks(service: TaskService = Depends(get_task_service)) -> TaskListResponse:
    return service.list_tasks()


@router.get("/{task_id}", response_model=TaskDetailResponse)
async def get_task(task_id: str, service: TaskService = Depends(get_task_service)) -> TaskDetailResponse:
    return service.get_task(task_id)


@router.post("/{task_id}/cancel", response_model=TaskDetailResponse, status_code=status.HTTP_200_OK)
async def cancel_task(task_id: str, service: TaskService = Depends(get_task_service)) -> TaskDetailResponse:
    return service.cancel_task(task_id)
