import asyncio
from fastapi import APIRouter, HTTPException
from app.services import ueransim

router = APIRouter()


@router.post("/emulated-session/start")
async def start_emulated_session():
    task_id = ueransim.create_task()
    asyncio.create_task(ueransim.run_test(task_id))
    return {"task_id": task_id}


@router.get("/emulated-session/status/{task_id}")
async def get_emulated_session_status(task_id: str):
    task = ueransim.get_task(task_id)
    if task is None:
        raise HTTPException(status_code=404, detail="Task not found")
    return task
