"""Task endpoints.""" from typing import Any from fastapi import APIRouter, Depends, Path from pydantic import UUID4 from product_staging.api.auth import ( identity_uuid_from_scope, ) from product_staging.api.schemas.task import ( CreateTemplateTaskRequest, TemplateTaskStatusResponse, ) from product_staging.logic import task as task_logic router = APIRouter(tags=["Tasks"]) @router.post( "/task-success/{token}", operation_id="task_success", summary="Mark a Fargate task execution as being successfully completed.", description="This endpoint serves as a callback for Fargate tasks to mark their execution as successfully completed.", ) async def task_success( payload: dict[str, Any], identity_uuid: UUID4 = Depends(identity_uuid_from_scope), token: UUID4 = Path( description="The token that identifies the Fargate task execution.", ), ): """Mark a Fargate task execution as being successfully completed.""" return await task_logic.mark_task_success( token=token, identity_uuid=identity_uuid, payload=payload, ) @router.post( "/task-failure/{token}", operation_id="task_failure", summary="Mark a Fargate task execution as having failed.", description="This endpoint serves as a callback for Fargate tasks to mark their execution as failed.", ) async def task_failure( payload: dict[str, Any], identity_uuid: UUID4 = Depends(identity_uuid_from_scope), token: UUID4 = Path( description="The token that identifies the Fargate task execution.", ), ): """Mark a Fargate task execution as being failed.""" return await task_logic.mark_task_failure( token=token, identity_uuid=identity_uuid, payload=payload, ) @router.post( "/template/task/create", operation_id="create_template_task", summary="Initialize a new task to create a template from Spotify URLs.", ) async def create_template_task( payload: CreateTemplateTaskRequest, identity_uuid: UUID4 = Depends(identity_uuid_from_scope), ) -> UUID4: """Create a new template task.""" return await task_logic.create_template_task( identity_uuid=identity_uuid, artist_urls=payload.artist_urls, album_urls=payload.album_urls, ) @router.get( path="/template/{token}/status", operation_id="get_template_task_status", summary="Get the status of a template task.", ) async def get_template_task_status( identity_uuid: UUID4 = Depends(identity_uuid_from_scope), token: UUID4 = Path( description="The token that identifies the Fargate task execution.", ), ) -> TemplateTaskStatusResponse: """Get the status of a template task.""" return await task_logic.get_template_task_status( identity_uuid=identity_uuid, token=token, )