from inspira.decorators.websocket import websocket
from inspira.websockets import WebSocket
from inspira.logging import log


@websocket("/{{root_path}}")
class {{controller_name}}Controller:

    async def on_open(self, websocket: WebSocket):
        log.info("Inside On Open")
        await websocket.on_open()

    async def on_message(self, websocket: WebSocket, message):
        log.info(f"Inside On Message. Received message: {message}")

        # Modify the message before echoing back
        modified_message = f"Server response to: {message.get('text', '')}"

        await websocket.send_text(modified_message)

    async def on_close(self, websocket: WebSocket):
        log.info("Inside On Close")
        await websocket.on_close()
