from __future__ import annotations

from app.llm.models import (
    LLMErrorKind,
    LLMProviderAvailability,
    LLMProviderCapabilities,
    LLMProviderError,
    LLMStructuredRequest,
    LLMStructuredResult,
    LLMTextRequest,
    LLMTextResult,
)


class OpenAIAdapterStub:
    def __init__(self, *, enabled: bool = False, default_model: str = "stub-openai-model") -> None:
        self._enabled = enabled
        self._default_model = default_model

    def provider_name(self) -> str:
        return "openai"

    def availability(self) -> LLMProviderAvailability:
        reason = None if self._enabled else "Stub OpenAI deshabilitado"
        return LLMProviderAvailability(
            configured=False,
            enabled=self._enabled,
            reason=reason,
            is_stub=True,
        )

    def capabilities(self) -> LLMProviderCapabilities:
        return LLMProviderCapabilities(
            text_generation=False,
            structured_generation=False,
            native_structured_output=False,
        )

    def close(self) -> None:
        return None

    def generate_text(self, request: LLMTextRequest) -> LLMTextResult:
        raise LLMProviderError(
            "Proveedor OpenAI no habilitado en esta fase",
            kind=LLMErrorKind.INVALID_CONFIGURATION,
            provider=self.provider_name(),
            model=request.model or self._default_model,
        )

    def generate_structured(self, request: LLMStructuredRequest) -> LLMStructuredResult:
        raise LLMProviderError(
            "Proveedor OpenAI no habilitado en esta fase",
            kind=LLMErrorKind.INVALID_CONFIGURATION,
            provider=self.provider_name(),
            model=request.model or self._default_model,
        )
