from fastapi import APIRouter, Response
from app.schemas.analyze_status import AnalyzeStatus, AnalyzeStatusData
from app.services.model import TaskStatus

router = APIRouter()


@router.get("/analyze/status/{task_id}")
async def get_task_status(task_id: str, response: Response):
    from app.main import WORKER
    task = WORKER.task_store.get(task_id)

    if task:
        response.status_code = 200
        return AnalyzeStatus(
            success=True,
            data=AnalyzeStatusData(
                taskId=task_id,
                status=task.status,
                progress=task.progress,
                message=task.message
            )
        )
    else:
        response.status_code = 404
        return AnalyzeStatus(
            success=False,
            data=AnalyzeStatusData(
                taskId=task_id,
                status=TaskStatus.NOT_FOUND.name,
                progress=0,
                message=TaskStatus.NOT_FOUND.value
            )
        )
