from abc import ABC
from HowdenLLM.providers.base_provider import BaseProvider
from openai import OpenAI
from .known_providers import KnownProviders

class OpenAIProvider(BaseProvider, ABC):
    provider = KnownProviders.OpenAI

    def __init__(self,client: OpenAI):
        self.client = client

    def complete(self, system: str, prompt: str, model: str, use_web_search_tool: bool) -> str:

        if use_web_search_tool:
            tools = [
                { "type": "web_search" }
            ]
        else:
            tools = None

        if model in ["gpt-5", "gpt-5-mini", "gpt-5-nano"]:
            response = self.client.responses.create(
                model=model,
                input=[
                    {"role": "system", "content": system},
                    {"role": "user", "content": prompt}
                ],
                tools=tools,
                max_output_tokens=16000
            )
        else:
            raise Exception(f"Unsupported model: {model}")

        return response.output_text
