# This file was auto-generated by Fern from our API Definition.

import os
import typing

import httpx
from .apple_pay.client import ApplePayClient, AsyncApplePayClient
from .bank_accounts.client import AsyncBankAccountsClient, BankAccountsClient
from .bookings.client import AsyncBookingsClient, BookingsClient
from .cards.client import AsyncCardsClient, CardsClient
from .cash_drawers.client import AsyncCashDrawersClient, CashDrawersClient
from .catalog.client import AsyncCatalogClient, CatalogClient
from .checkout.client import AsyncCheckoutClient, CheckoutClient
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .customers.client import AsyncCustomersClient, CustomersClient
from .devices.client import AsyncDevicesClient, DevicesClient
from .disputes.client import AsyncDisputesClient, DisputesClient
from .employees.client import AsyncEmployeesClient, EmployeesClient
from .environment import SquareEnvironment
from .events.client import AsyncEventsClient, EventsClient
from .gift_cards.client import AsyncGiftCardsClient, GiftCardsClient
from .inventory.client import AsyncInventoryClient, InventoryClient
from .invoices.client import AsyncInvoicesClient, InvoicesClient
from .labor.client import AsyncLaborClient, LaborClient
from .locations.client import AsyncLocationsClient, LocationsClient
from .loyalty.client import AsyncLoyaltyClient, LoyaltyClient
from .merchants.client import AsyncMerchantsClient, MerchantsClient
from .mobile.client import AsyncMobileClient, MobileClient
from .o_auth.client import AsyncOAuthClient, OAuthClient
from .orders.client import AsyncOrdersClient, OrdersClient
from .payments.client import AsyncPaymentsClient, PaymentsClient
from .payouts.client import AsyncPayoutsClient, PayoutsClient
from .refunds.client import AsyncRefundsClient, RefundsClient
from .sites.client import AsyncSitesClient, SitesClient
from .snippets.client import AsyncSnippetsClient, SnippetsClient
from .subscriptions.client import AsyncSubscriptionsClient, SubscriptionsClient
from .team.client import AsyncTeamClient, TeamClient
from .team_members.client import AsyncTeamMembersClient, TeamMembersClient
from .terminal.client import AsyncTerminalClient, TerminalClient
from .v1transactions.client import AsyncV1TransactionsClient, V1TransactionsClient
from .vendors.client import AsyncVendorsClient, VendorsClient
from .webhooks.client import AsyncWebhooksClient, WebhooksClient


class Square:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : typing.Optional[str]
        The base url to use for requests from the client.

    environment : SquareEnvironment
        The environment to use for requests from the client. from .environment import SquareEnvironment



        Defaults to SquareEnvironment.PRODUCTION



    token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.Client]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    version : typing.Optional[str]
    Examples
    --------
    from square import Square

    client = Square(
        token="YOUR_TOKEN",
    )
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: SquareEnvironment = SquareEnvironment.PRODUCTION,
        token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("SQUARE_TOKEN"),
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.Client] = None,
        version: typing.Optional[str] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        self._client_wrapper = SyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            token=token,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.Client(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
            version=version,
        )
        self.mobile = MobileClient(client_wrapper=self._client_wrapper)
        self.o_auth = OAuthClient(client_wrapper=self._client_wrapper)
        self.v1transactions = V1TransactionsClient(client_wrapper=self._client_wrapper)
        self.apple_pay = ApplePayClient(client_wrapper=self._client_wrapper)
        self.bank_accounts = BankAccountsClient(client_wrapper=self._client_wrapper)
        self.bookings = BookingsClient(client_wrapper=self._client_wrapper)
        self.cards = CardsClient(client_wrapper=self._client_wrapper)
        self.catalog = CatalogClient(client_wrapper=self._client_wrapper)
        self.customers = CustomersClient(client_wrapper=self._client_wrapper)
        self.devices = DevicesClient(client_wrapper=self._client_wrapper)
        self.disputes = DisputesClient(client_wrapper=self._client_wrapper)
        self.employees = EmployeesClient(client_wrapper=self._client_wrapper)
        self.events = EventsClient(client_wrapper=self._client_wrapper)
        self.gift_cards = GiftCardsClient(client_wrapper=self._client_wrapper)
        self.inventory = InventoryClient(client_wrapper=self._client_wrapper)
        self.invoices = InvoicesClient(client_wrapper=self._client_wrapper)
        self.labor = LaborClient(client_wrapper=self._client_wrapper)
        self.locations = LocationsClient(client_wrapper=self._client_wrapper)
        self.loyalty = LoyaltyClient(client_wrapper=self._client_wrapper)
        self.merchants = MerchantsClient(client_wrapper=self._client_wrapper)
        self.checkout = CheckoutClient(client_wrapper=self._client_wrapper)
        self.orders = OrdersClient(client_wrapper=self._client_wrapper)
        self.payments = PaymentsClient(client_wrapper=self._client_wrapper)
        self.payouts = PayoutsClient(client_wrapper=self._client_wrapper)
        self.refunds = RefundsClient(client_wrapper=self._client_wrapper)
        self.sites = SitesClient(client_wrapper=self._client_wrapper)
        self.snippets = SnippetsClient(client_wrapper=self._client_wrapper)
        self.subscriptions = SubscriptionsClient(client_wrapper=self._client_wrapper)
        self.team_members = TeamMembersClient(client_wrapper=self._client_wrapper)
        self.team = TeamClient(client_wrapper=self._client_wrapper)
        self.terminal = TerminalClient(client_wrapper=self._client_wrapper)
        self.vendors = VendorsClient(client_wrapper=self._client_wrapper)
        self.cash_drawers = CashDrawersClient(client_wrapper=self._client_wrapper)
        self.webhooks = WebhooksClient(client_wrapper=self._client_wrapper)


class AsyncSquare:
    """
    Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.

    Parameters
    ----------
    base_url : typing.Optional[str]
        The base url to use for requests from the client.

    environment : SquareEnvironment
        The environment to use for requests from the client. from .environment import SquareEnvironment



        Defaults to SquareEnvironment.PRODUCTION



    token : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
    headers : typing.Optional[typing.Dict[str, str]]
        Additional headers to send with every request.

    timeout : typing.Optional[float]
        The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.

    follow_redirects : typing.Optional[bool]
        Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.

    httpx_client : typing.Optional[httpx.AsyncClient]
        The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.

    version : typing.Optional[str]
    Examples
    --------
    from square import AsyncSquare

    client = AsyncSquare(
        token="YOUR_TOKEN",
    )
    """

    def __init__(
        self,
        *,
        base_url: typing.Optional[str] = None,
        environment: SquareEnvironment = SquareEnvironment.PRODUCTION,
        token: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = os.getenv("SQUARE_TOKEN"),
        headers: typing.Optional[typing.Dict[str, str]] = None,
        timeout: typing.Optional[float] = None,
        follow_redirects: typing.Optional[bool] = True,
        httpx_client: typing.Optional[httpx.AsyncClient] = None,
        version: typing.Optional[str] = None,
    ):
        _defaulted_timeout = (
            timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
        )
        self._client_wrapper = AsyncClientWrapper(
            base_url=_get_base_url(base_url=base_url, environment=environment),
            token=token,
            headers=headers,
            httpx_client=httpx_client
            if httpx_client is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
            if follow_redirects is not None
            else httpx.AsyncClient(timeout=_defaulted_timeout),
            timeout=_defaulted_timeout,
            version=version,
        )
        self.mobile = AsyncMobileClient(client_wrapper=self._client_wrapper)
        self.o_auth = AsyncOAuthClient(client_wrapper=self._client_wrapper)
        self.v1transactions = AsyncV1TransactionsClient(client_wrapper=self._client_wrapper)
        self.apple_pay = AsyncApplePayClient(client_wrapper=self._client_wrapper)
        self.bank_accounts = AsyncBankAccountsClient(client_wrapper=self._client_wrapper)
        self.bookings = AsyncBookingsClient(client_wrapper=self._client_wrapper)
        self.cards = AsyncCardsClient(client_wrapper=self._client_wrapper)
        self.catalog = AsyncCatalogClient(client_wrapper=self._client_wrapper)
        self.customers = AsyncCustomersClient(client_wrapper=self._client_wrapper)
        self.devices = AsyncDevicesClient(client_wrapper=self._client_wrapper)
        self.disputes = AsyncDisputesClient(client_wrapper=self._client_wrapper)
        self.employees = AsyncEmployeesClient(client_wrapper=self._client_wrapper)
        self.events = AsyncEventsClient(client_wrapper=self._client_wrapper)
        self.gift_cards = AsyncGiftCardsClient(client_wrapper=self._client_wrapper)
        self.inventory = AsyncInventoryClient(client_wrapper=self._client_wrapper)
        self.invoices = AsyncInvoicesClient(client_wrapper=self._client_wrapper)
        self.labor = AsyncLaborClient(client_wrapper=self._client_wrapper)
        self.locations = AsyncLocationsClient(client_wrapper=self._client_wrapper)
        self.loyalty = AsyncLoyaltyClient(client_wrapper=self._client_wrapper)
        self.merchants = AsyncMerchantsClient(client_wrapper=self._client_wrapper)
        self.checkout = AsyncCheckoutClient(client_wrapper=self._client_wrapper)
        self.orders = AsyncOrdersClient(client_wrapper=self._client_wrapper)
        self.payments = AsyncPaymentsClient(client_wrapper=self._client_wrapper)
        self.payouts = AsyncPayoutsClient(client_wrapper=self._client_wrapper)
        self.refunds = AsyncRefundsClient(client_wrapper=self._client_wrapper)
        self.sites = AsyncSitesClient(client_wrapper=self._client_wrapper)
        self.snippets = AsyncSnippetsClient(client_wrapper=self._client_wrapper)
        self.subscriptions = AsyncSubscriptionsClient(client_wrapper=self._client_wrapper)
        self.team_members = AsyncTeamMembersClient(client_wrapper=self._client_wrapper)
        self.team = AsyncTeamClient(client_wrapper=self._client_wrapper)
        self.terminal = AsyncTerminalClient(client_wrapper=self._client_wrapper)
        self.vendors = AsyncVendorsClient(client_wrapper=self._client_wrapper)
        self.cash_drawers = AsyncCashDrawersClient(client_wrapper=self._client_wrapper)
        self.webhooks = AsyncWebhooksClient(client_wrapper=self._client_wrapper)


def _get_base_url(*, base_url: typing.Optional[str] = None, environment: SquareEnvironment) -> str:
    if base_url is not None:
        return base_url
    elif environment is not None:
        return environment.value
    else:
        raise Exception("Please pass in either base_url or environment to construct the client")
