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

from .basesdk import BaseSDK
from .httpclient import AsyncHttpClient, HttpClient
from .sdkconfiguration import SDKConfiguration
from .utils.logger import Logger, get_default_logger
from .utils.retries import RetryConfig
from ascend_sdk import utils
from ascend_sdk._hooks import SDKHooks
from ascend_sdk.account_creation import AccountCreation
from ascend_sdk.account_management import AccountManagement
from ascend_sdk.account_transfers import AccountTransfers
from ascend_sdk.ach_transfers import ACHTransfers
from ascend_sdk.assets import Assets
from ascend_sdk.authentication import Authentication
from ascend_sdk.bank_relationships import BankRelationships
from ascend_sdk.basket_orders import BasketOrders
from ascend_sdk.cash_balances import CashBalances
from ascend_sdk.create_order import CreateOrder
from ascend_sdk.data_retrieval import DataRetrieval
from ascend_sdk.enrollments_and_agreements import EnrollmentsAndAgreements
from ascend_sdk.fees_and_credits import FeesAndCredits
from ascend_sdk.fixed_income_pricing import FixedIncomePricing
from ascend_sdk.instant_cash_transfer_ict_ import InstantCashTransferICT
from ascend_sdk.investigations import Investigations
from ascend_sdk.investor_docs import InvestorDocs
from ascend_sdk.journals import Journals
from ascend_sdk.ledger import Ledger
from ascend_sdk.margins import Margins
from ascend_sdk.models import components
from ascend_sdk.person_management import PersonManagement
from ascend_sdk.reader import Reader
from ascend_sdk.retirements import Retirements
from ascend_sdk.schedule_transfers import ScheduleTransfers
from ascend_sdk.subscriber import Subscriber
from ascend_sdk.test_simulation import TestSimulation
from ascend_sdk.types import OptionalNullable, UNSET
from ascend_sdk.wires import Wires
import httpx
from typing import Callable, Dict, Optional, Union


class SDK(BaseSDK):
    r"""Ascend OpenAPI: Combined Ascend OpenAPI spec for SDK generation"""

    authentication: Authentication
    reader: Reader
    subscriber: Subscriber
    person_management: PersonManagement
    account_creation: AccountCreation
    account_management: AccountManagement
    enrollments_and_agreements: EnrollmentsAndAgreements
    investigations: Investigations
    account_transfers: AccountTransfers
    bank_relationships: BankRelationships
    ach_transfers: ACHTransfers
    instant_cash_transfer_ict: InstantCashTransferICT
    retirements: Retirements
    schedule_transfers: ScheduleTransfers
    wires: Wires
    journals: Journals
    cash_balances: CashBalances
    fees_and_credits: FeesAndCredits
    test_simulation: TestSimulation
    create_order: CreateOrder
    fixed_income_pricing: FixedIncomePricing
    basket_orders: BasketOrders
    assets: Assets
    ledger: Ledger
    investor_docs: InvestorDocs
    data_retrieval: DataRetrieval
    margins: Margins

    def __init__(
        self,
        security: Optional[
            Union[components.Security, Callable[[], components.Security]]
        ] = None,
        server: Optional[str] = None,
        server_url: Optional[str] = None,
        url_params: Optional[Dict[str, str]] = None,
        client: Optional[HttpClient] = None,
        async_client: Optional[AsyncHttpClient] = None,
        retry_config: OptionalNullable[RetryConfig] = UNSET,
        timeout_ms: Optional[int] = None,
        debug_logger: Optional[Logger] = None,
    ) -> None:
        r"""Instantiates the SDK configuring it with the provided parameters.

        :param security: The security details required for authentication
        :param server: The server by name to use for all methods
        :param server_url: The server URL to use for all methods
        :param url_params: Parameters to optionally template the server URL with
        :param client: The HTTP client to use for all synchronous methods
        :param async_client: The Async HTTP client to use for all asynchronous methods
        :param retry_config: The retry configuration to use for all supported methods
        :param timeout_ms: Optional request timeout applied to each operation in milliseconds
        """
        if client is None:
            client = httpx.Client()

        assert issubclass(
            type(client), HttpClient
        ), "The provided client must implement the HttpClient protocol."

        if async_client is None:
            async_client = httpx.AsyncClient()

        if debug_logger is None:
            debug_logger = get_default_logger()

        assert issubclass(
            type(async_client), AsyncHttpClient
        ), "The provided async_client must implement the AsyncHttpClient protocol."

        if server_url is not None:
            if url_params is not None:
                server_url = utils.template_url(server_url, url_params)

        BaseSDK.__init__(
            self,
            SDKConfiguration(
                client=client,
                async_client=async_client,
                security=security,
                server_url=server_url,
                server=server,
                retry_config=retry_config,
                timeout_ms=timeout_ms,
                debug_logger=debug_logger,
            ),
        )

        hooks = SDKHooks()

        current_server_url, *_ = self.sdk_configuration.get_server_details()
        server_url, self.sdk_configuration.client = hooks.sdk_init(
            current_server_url, self.sdk_configuration.client
        )
        if current_server_url != server_url:
            self.sdk_configuration.server_url = server_url

        # pylint: disable=protected-access
        self.sdk_configuration.__dict__["_hooks"] = hooks

        self._init_sdks()

    def _init_sdks(self):
        self.authentication = Authentication(self.sdk_configuration)
        self.reader = Reader(self.sdk_configuration)
        self.subscriber = Subscriber(self.sdk_configuration)
        self.person_management = PersonManagement(self.sdk_configuration)
        self.account_creation = AccountCreation(self.sdk_configuration)
        self.account_management = AccountManagement(self.sdk_configuration)
        self.enrollments_and_agreements = EnrollmentsAndAgreements(
            self.sdk_configuration
        )
        self.investigations = Investigations(self.sdk_configuration)
        self.account_transfers = AccountTransfers(self.sdk_configuration)
        self.bank_relationships = BankRelationships(self.sdk_configuration)
        self.ach_transfers = ACHTransfers(self.sdk_configuration)
        self.instant_cash_transfer_ict = InstantCashTransferICT(self.sdk_configuration)
        self.retirements = Retirements(self.sdk_configuration)
        self.schedule_transfers = ScheduleTransfers(self.sdk_configuration)
        self.wires = Wires(self.sdk_configuration)
        self.journals = Journals(self.sdk_configuration)
        self.cash_balances = CashBalances(self.sdk_configuration)
        self.fees_and_credits = FeesAndCredits(self.sdk_configuration)
        self.test_simulation = TestSimulation(self.sdk_configuration)
        self.create_order = CreateOrder(self.sdk_configuration)
        self.fixed_income_pricing = FixedIncomePricing(self.sdk_configuration)
        self.basket_orders = BasketOrders(self.sdk_configuration)
        self.assets = Assets(self.sdk_configuration)
        self.ledger = Ledger(self.sdk_configuration)
        self.investor_docs = InvestorDocs(self.sdk_configuration)
        self.data_retrieval = DataRetrieval(self.sdk_configuration)
        self.margins = Margins(self.sdk_configuration)
