# Copyright 2026 Igor Bogdanov
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from abc import ABC, abstractmethod
from typing import List, Dict, Tuple

class AdapterBase(ABC):
    """
    Abstract Base Class for all LLM Provider Adapters.
    Ensures a consistent interface across different API standards.
    """
    
    @abstractmethod
    def chat_completion(
        self,
        messages: List[Dict[str, str]],
        model: str,
        temperature: float,
        max_tokens: int,
        top_p: float,
        **kwargs
    ) -> Tuple[str, int, int, int, float]:
        """
        Execute a chat completion request to the underlying provider.

        Args:
            messages: A list of message dictionaries e.g., [{"role": "user", "content": "Hello"}].
            model: The name or ID of the model to use.
            temperature: Sampling temperature.
            max_tokens: Maximum tokens to generate.
            top_p: Nucleus sampling probability.
            **kwargs: Additional provider-specific kwargs (e.g., session object, timeouts).

        Returns:
            Tuple containing:
            - response_text (str): The text generated by the model.
            - prompt_tokens (int): Tokens used in the prompt.
            - completion_tokens (int): Tokens used in the response.
            - total_tokens (int): Total tokens used.
            - latency (float): Time taken for the request in seconds.
        """
        pass

    def cleanup(self) -> None:
        """
        Optionally override this method to clean up resources, clients, or active sessions.
        """
        pass