"""Backend interface used by the scheduler."""

from __future__ import annotations

from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Any

from ..contracts import BackendCapabilities


@dataclass(frozen=True)
class BackendInput:
    prompt: str
    max_new_tokens: int
    tenant_id: str
    request_id: str
    stack_key: str
    activation_specs: tuple[dict[str, Any], ...] = ()
    metadata: dict[str, str] = field(default_factory=dict)


@dataclass(frozen=True)
class BackendResult:
    text: str
    input_tokens: int
    output_tokens: int
    latency_ms: float
    gpu_memory_bytes: int | None = None
    metadata: dict[str, Any] = field(default_factory=dict)


class Backend(ABC):
    @property
    @abstractmethod
    def capabilities(self) -> BackendCapabilities:
        raise NotImplementedError

    @abstractmethod
    async def generate_batch(self, requests: list[BackendInput]) -> list[BackendResult]:
        raise NotImplementedError

