"""Typed events used inside the TUI app and between components."""

from __future__ import annotations

from textual.message import Message


class WsEvent(Message):
    """Raw WebSocket event forwarded from the backend."""

    def __init__(self, payload: dict) -> None:
        self.payload = payload
        super().__init__()


class ConnectionStatusChanged(Message):
    """Fired when WebSocket connection state changes."""

    def __init__(self, connected: bool, detail: str = "") -> None:
        self.connected = connected
        self.detail = detail
        super().__init__()


class UserSubmitted(Message):
    """User pressed Enter in the input box."""

    def __init__(self, text: str) -> None:
        self.text = text
        super().__init__()


class CommandTriggered(Message):
    """User typed a slash command."""

    def __init__(self, name: str, args: str) -> None:
        self.name = name
        self.args = args
        super().__init__()


class PermissionRequest(Message):
    """Tool call requires destructive-operation confirmation (component fallback)."""

    def __init__(self, tool: str, args: dict, message: str) -> None:
        self.tool = tool
        self.args = args
        self.message = message
        super().__init__()
