"""Base provider abstraction."""

from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Any


class BaseProvider(ABC):
    """Abstract base class for LLM providers.

    Attributes:
        name: Provider name (e.g., "anthropic", "openai", "local").
        model: Model name (e.g., "claude-3-sonnet").
    """

    name: str = "base"
    model: str = "unknown"

    def __init__(self, model: str, **kwargs: Any) -> None:
        """Initialize provider with model name.

        Args:
            model: Model name or identifier.
            **kwargs: Additional provider-specific configuration.
        """
        self.model = model
        self.config = kwargs

    @abstractmethod
    def judge(
        self,
        system: str,
        user: str,
    ) -> dict[str, Any]:
        """Call LLM to judge/score output.

        Args:
            system: System prompt defining task.
            user: User prompt with context and output to evaluate.

        Returns:
            Dictionary with keys:
            - score: float between 0.0 and 1.0
            - evidence: str explanation of score
            - cost_usd: float (optional, default 0.0)
            - tokens: dict with "input" and "output" counts (optional)

        Raises:
            ProviderAPIError: If API call fails.
            ProviderNotConfiguredError: If API key is missing.
        """
        pass

    @abstractmethod
    def generate(
        self,
        prompt: str,
        system: str | None = None,
    ) -> str:
        """Generate text from prompt.

        Args:
            prompt: Input prompt.
            system: Optional system prompt.

        Returns:
            Generated text.

        Raises:
            ProviderAPIError: If API call fails.
            ProviderNotConfiguredError: If API key is missing.
        """
        pass

    def __repr__(self) -> str:
        """Return string representation."""
        return f"{self.__class__.__name__}(model={self.model})"
