"""Originally generated by Speakeasy; now maintained manually."""

from ._version import (
    __gen_version__,
    __openapi_doc_version__,
    __user_agent__,
    __version__,
)
from .httpclient import AsyncHttpClient, HttpClient
from .utils import Logger, RetryConfig, remove_suffix
from dataclasses import dataclass, field
from lambdadb import models
from lambdadb.types import OptionalNullable, UNSET
from pydantic import Field
from typing import Callable, Dict, List, Optional, Tuple, Union


DEFAULT_BASE_URL = "https://api.lambdadb.ai"
DEFAULT_PROJECT_NAME = "playground"

SERVERS = [
    "https://{projectHost}",
    # LambdaDB API endpoints (legacy)
]
"""Contains the list of servers available to the SDK"""


@dataclass
class SDKConfiguration:
    client: Union[HttpClient, None]
    client_supplied: bool
    async_client: Union[AsyncHttpClient, None]
    async_client_supplied: bool
    debug_logger: Logger
    security: Optional[Union[models.Security, Callable[[], models.Security]]] = None
    server_url: Optional[str] = ""
    server_idx: Optional[int] = 0
    server_defaults: List[Dict[str, str]] = field(default_factory=List)
    base_url: Optional[str] = None
    project_name: Optional[str] = None
    language: str = "python"
    openapi_doc_version: str = __openapi_doc_version__
    sdk_version: str = __version__
    gen_version: str = __gen_version__
    user_agent: str = __user_agent__
    retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET)
    timeout_ms: Optional[int] = None

    def get_server_details(self) -> Tuple[str, Dict[str, str]]:
        if self.server_url is not None and self.server_url:
            return remove_suffix(self.server_url, "/"), {}
        if self.base_url is not None and self.project_name is not None:
            base = (self.base_url or DEFAULT_BASE_URL).rstrip("/")
            project = self.project_name or DEFAULT_PROJECT_NAME
            return f"{base}/projects/{project}", {}
        if self.server_idx is None:
            self.server_idx = 0
        return SERVERS[self.server_idx], self.server_defaults[self.server_idx]
