"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from dataclasses import dataclass
from pathlib import Path
from typing import Dict, Optional, Tuple, Union

from pydantic import Field

from anncsu.common.httpclient import AsyncHttpClient, HttpClient
from anncsu.common.types import UNSET, OptionalNullable
from anncsu.common.utils import Logger, RetryConfig, remove_suffix


# Lazy import to avoid circular dependency
def _get_version_info():
    """Lazy import of version info from PA package to avoid circular imports."""
    from anncsu.pa._version import (
        __gen_version__,
        __openapi_doc_version__,
        __user_agent__,
        __version__,
    )

    return __version__, __openapi_doc_version__, __gen_version__, __user_agent__


# Default values in case version module not yet loaded
__version__ = "0.0.0"
__openapi_doc_version__ = "1.0.0"
__gen_version__ = "0.0.0"
__user_agent__ = "anncsu"


SERVERS = [
    "https://modipa.agenziaentrate.gov.it/govway/rest/in/AgenziaEntrate-PDND/anncsu-consultazione/v1",
    # l'accesso all'API e' protetta dai controlli di accesso su GovWay
]
"""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
    server_url: Optional[str] = ""
    server_idx: Optional[int] = 0
    language: str = "python"
    openapi_doc_version: Optional[str] = None
    sdk_version: Optional[str] = None
    gen_version: Optional[str] = None
    user_agent: Optional[str] = None
    retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET)
    timeout_ms: Optional[int] = None
    validate_responses: bool = False
    """Enable response validation against OpenAPI spec (requires dev dependencies)"""
    openapi_spec_path: Path | None = None
    """Path to OpenAPI specification file for validation"""

    def __post_init__(self):
        """Initialize version info lazily to avoid circular imports."""
        if self.openapi_doc_version is None:
            try:
                ver, openapi, gen, ua = _get_version_info()
                self.sdk_version = ver
                self.openapi_doc_version = openapi
                self.gen_version = gen
                self.user_agent = ua
            except ImportError:
                # Fallback to defaults if PA package not yet loaded
                self.sdk_version = __version__
                self.openapi_doc_version = __openapi_doc_version__
                self.gen_version = __gen_version__
                self.user_agent = __user_agent__

    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.server_idx is None:
            self.server_idx = 0

        return SERVERS[self.server_idx], {}
