from typing import Literal

from pydantic import BaseModel, model_validator
from sinapsis_chatbots_base.helpers.schemas import LLMCompletionArgs


class AnthropicCompletionArgs(LLMCompletionArgs):
    """Anthropic-specific generation arguments.

    Attributes:
        temperature (float | None): Sampling temperature.
        top_p (float | None): Nucleus sampling parameter.
        top_k (int | None): Top-k sampling parameter.
        response_format (LLMResponseFormat): Provider-neutral structured output config.
        max_tokens (int): Maximum number of tokens to generate.
        service_tier (Literal["auto", "standard_only"]): Anthropic service tier.
        stop_sequences (list[str] | None): Custom stop sequences.
    """

    max_tokens: int
    service_tier: Literal["auto", "standard_only"] = "standard_only"
    stop_sequences: list[str] | None = None

    @model_validator(mode="after")
    def validate_sampling_args(self) -> "AnthropicCompletionArgs":
        """Validate Anthropic-specific sampling constraints.

        Returns:
            AnthropicCompletionArgs: Validated completion arguments.

        Raises:
            ValueError: If mutually exclusive sampling args are provided together.
        """
        if self.temperature is not None and self.top_p is not None:
            raise ValueError("Anthropic completion args cannot set both `temperature` and `top_p` at the same time.")
        return self


class AnthropicThinkingArgs(BaseModel):
    """Anthropic extended-thinking configuration.

    Attributes:
        budget_tokens (int): Maximum tokens reserved for reasoning blocks.
        type (Literal["enabled", "disabled"]): Whether extended thinking is enabled.
    """

    budget_tokens: int = 2048
    type: Literal["enabled", "disabled"] = "disabled"
