from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Protocol, runtime_checkable


@dataclass(frozen=True, slots=True)
class BackendReply:
    stage: str
    text: str = ""
    done: bool = False
    export_payload: Any = None
    metadata: Any = None


@runtime_checkable
class AgentBackend(Protocol):
    async def prepare(
        self,
        elegibility: bool,
        protocol: str,
    ) -> None: ...

    async def run(self, user_input: Any) -> BackendReply: ...

    async def set_interruption(
        self,
        interrupted: bool,
        listened_text: str = "",
        skipped: bool = False,
        speech_id: str = "",
    ) -> None: ...

    async def set_processing_interruption(
        self,
        listened_text: str = "",
        skipped: bool = False,
        speech_id: str = "",
    ) -> None: ...

    async def inject_idle_nudge(self, nudge_text: str) -> None: ...

    async def end_service_once(self) -> BackendReply: ...
