import logging

from fastapi import APIRouter

from gateway_core.domain.Reboot import RebootDto
from gateway_core.domain.SoftwareUpgrade import SoftwareUpgradeDto

logger = logging.getLogger(__name__)

def buildRouter(*, rebootUseCase, upgradeUseCase) -> APIRouter:
    router = APIRouter()

    @router.get("/v1/health")
    async def health():
        return {"status": "ok"}

    @router.post("/v1/actions/reboot")
    async def reboot(dto: RebootDto):
        logger.info("NodeAgent reboot request: %s", dto.__dict__)
        await rebootUseCase.execute(dto)
        return {"accepted": True, "taskId": dto.taskId}

    @router.post("/v1/actions/upgrade")
    async def upgrade(dto: SoftwareUpgradeDto):
        logger.info("NodeAgent upgrade request: %s", dto.__dict__)
        await upgradeUseCase.execute(dto)
        return {"accepted": True, "taskId": dto.taskId}

    return router
