"""AAL session for logging actions."""

from __future__ import annotations

from collections.abc import Callable

from .types import LogActionInput, QueuedEvent

PushFn = Callable[[QueuedEvent], None]


class AALSession:
    """Represents an agent session for logging actions."""

    def __init__(self, session_id: str, agent_id: str, push_fn: PushFn) -> None:
        self.id = session_id
        self.agent_id = agent_id
        self._push_fn = push_fn

    def log_action(self, input: LogActionInput) -> None:
        """Log an action event to the buffer."""
        event: QueuedEvent = {
            "session_id": self.id,
            "agent_id": self.agent_id,
            "action_type": input["action_type"],
            "status": input["status"],
        }

        if "tool_name" in input:
            event["tool_name"] = input["tool_name"]
        if "parameters" in input:
            event["parameters"] = input["parameters"]
        if "response" in input:
            event["response"] = input["response"]
        if "latency_ms" in input:
            event["latency_ms"] = input["latency_ms"]

        self._push_fn(event)
