from fastapi import APIRouter, Request, Response
from toid_cli.services.runners import main_runner

router = APIRouter()

@router.post("/run/robot")
async def run_main(req: Request):
    status = False
    if(req.query_params.get("use_mock", False).lower() == "true"):
        status = await main_runner.run_robot(use_mock=True)
    else:
        status = await main_runner.run_robot(use_mock=False)
    if status:
        return Response(status_code=200) 
    return Response(status_code=400)

@router.post("/stop/robot")
async def run_main(req: Request):
    status = await main_runner.stop_robot()
    if status:
        return Response(status_code=200) 
    return Response(status_code=400)

@router.get("/status/robot")
async def run_main(req: Request):
    status = "OK" if main_runner.status() else "NOT RUNNING"
    return Response(content=status, status_code=200) 