"""Deepseek AI provider — OpenAI-compatible API."""

from __future__ import annotations

import openai

from .base import AIProvider
from .base_provider import BaseAPIProvider


class DeepseekProvider(BaseAPIProvider, AIProvider):
    """Deepseek chat provider using the OpenAI-compatible endpoint."""

    name = "deepseek"
    BASE_URL = "https://api.deepseek.com/v1/"
    ENV_VAR = "DEEPSEEK_API_KEY"
    DEFAULT_MODEL = "deepseek-chat"

    def _create_client(self) -> openai.OpenAI:
        http_client = self._make_http_client(timeout=90.0)
        kwargs = dict(
            api_key=self.api_key,
            base_url=self.BASE_URL,
            timeout=90.0,  # Extended for China: packet loss requires longer timeouts
        )
        if http_client:
            kwargs["http_client"] = http_client
        return openai.OpenAI(**kwargs)
