import logging

from fastapi import APIRouter, Request
from zmq import Socket

from control_backend.schemas.ri_message import SpeechCommand

logger = logging.getLogger(__name__)

router = APIRouter()


@router.post("/command", status_code=202)
async def receive_command(command: SpeechCommand, request: Request):
    # Validate and retrieve data.
    SpeechCommand.model_validate(command)
    topic = b"command"
    pub_socket: Socket = request.app.state.internal_comm_socket
    pub_socket.send_multipart([topic, command.model_dump_json().encode()])

    return {"status": "Command received"}
