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

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


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]]]
    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"),
        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,
            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]]]
    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"),
        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,
            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")
