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

import datetime as dt
import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.additional_data import AdditionalData
from ..types.idempotency_key import IdempotencyKey
from ..types.page_content import PageContent
from ..types.page_identifier import PageIdentifier
from ..types.page_setting import PageSetting
from ..types.payabli_api_response_00_responsedatanonobject import PayabliApiResponse00Responsedatanonobject
from ..types.payabli_credentials import PayabliCredentials
from ..types.payabli_pages import PayabliPages
from ..types.receipt_content import ReceiptContent
from ..types.subdomain import Subdomain
from .raw_client import AsyncRawHostedPaymentPagesClient, RawHostedPaymentPagesClient

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class HostedPaymentPagesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawHostedPaymentPagesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawHostedPaymentPagesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawHostedPaymentPagesClient
        """
        return self._raw_client

    def load_page(
        self, entry: str, subdomain: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> PayabliPages:
        """
        Loads all of a payment page's details including `pageIdentifier` and `validationCode`. This endpoint requires an `application` API token.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        subdomain : str
            Payment page identifier. The subdomain value is the last part of the payment page URL. For example, in`https://paypages-sandbox.payabli.com/513823dc10/pay-your-fees-1`, the subdomain is `pay-your-fees-1`.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PayabliPages
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.hosted_payment_pages.load_page(
            entry="8cfec329267",
            subdomain="pay-your-fees-1",
        )
        """
        _response = self._raw_client.load_page(entry, subdomain, request_options=request_options)
        return _response.data

    def new_page(
        self,
        entry: str,
        *,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        additional_data: typing.Optional[AdditionalData] = OMIT,
        credentials: typing.Optional[typing.Sequence[PayabliCredentials]] = OMIT,
        last_access: typing.Optional[dt.datetime] = OMIT,
        page_content: typing.Optional[PageContent] = OMIT,
        page_identifier: typing.Optional[PageIdentifier] = OMIT,
        page_settings: typing.Optional[PageSetting] = OMIT,
        published: typing.Optional[int] = OMIT,
        receipt_content: typing.Optional[ReceiptContent] = OMIT,
        subdomain: typing.Optional[Subdomain] = OMIT,
        total_amount: typing.Optional[float] = OMIT,
        validation_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PayabliApiResponse00Responsedatanonobject:
        """

        Creates a new payment page for a paypoint.
        Note: this operation doesn't create a new paypoint, just a payment page for an existing paypoint. Paypoints are created by the Payabli team when a boarding application is approved.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        idempotency_key : typing.Optional[IdempotencyKey]

        additional_data : typing.Optional[AdditionalData]

        credentials : typing.Optional[typing.Sequence[PayabliCredentials]]
            Array of credential objects with active services for the page

        last_access : typing.Optional[dt.datetime]
            Timestamp of last access to page structure

        page_content : typing.Optional[PageContent]
            Sections of page

        page_identifier : typing.Optional[PageIdentifier]

        page_settings : typing.Optional[PageSetting]
            Settings of page

        published : typing.Optional[int]
            Flag indicating if page is active to accept payments. `0` for false, `1` for true.

        receipt_content : typing.Optional[ReceiptContent]
            Sections of payment receipt

        subdomain : typing.Optional[Subdomain]
            Page identifier. Must be unique in platform.

        total_amount : typing.Optional[float]
            Total amount to pay in this page

        validation_code : typing.Optional[str]
            Base64 encoded image of CAPTCHA associated to this page load

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PayabliApiResponse00Responsedatanonobject
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.hosted_payment_pages.new_page(
            entry="8cfec329267",
            idempotency_key="6B29FC40-CA47-1067-B31D-00DD010662DA",
        )
        """
        _response = self._raw_client.new_page(
            entry,
            idempotency_key=idempotency_key,
            additional_data=additional_data,
            credentials=credentials,
            last_access=last_access,
            page_content=page_content,
            page_identifier=page_identifier,
            page_settings=page_settings,
            published=published,
            receipt_content=receipt_content,
            subdomain=subdomain,
            total_amount=total_amount,
            validation_code=validation_code,
            request_options=request_options,
        )
        return _response.data

    def save_page(
        self,
        entry: str,
        subdomain_: str,
        *,
        additional_data: typing.Optional[AdditionalData] = OMIT,
        credentials: typing.Optional[typing.Sequence[PayabliCredentials]] = OMIT,
        last_access: typing.Optional[dt.datetime] = OMIT,
        page_content: typing.Optional[PageContent] = OMIT,
        page_identifier: typing.Optional[PageIdentifier] = OMIT,
        page_settings: typing.Optional[PageSetting] = OMIT,
        published: typing.Optional[int] = OMIT,
        receipt_content: typing.Optional[ReceiptContent] = OMIT,
        subdomain: typing.Optional[Subdomain] = OMIT,
        total_amount: typing.Optional[float] = OMIT,
        validation_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PayabliApiResponse00Responsedatanonobject:
        """
        Updates a payment page in a paypoint.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        subdomain_ : str
            Payment page identifier. The subdomain value is the last part of the payment page URL. For example, in`https://paypages-sandbox.payabli.com/513823dc10/pay-your-fees-1`, the subdomain is `pay-your-fees-1`.

        additional_data : typing.Optional[AdditionalData]

        credentials : typing.Optional[typing.Sequence[PayabliCredentials]]
            Array of credential objects with active services for the page

        last_access : typing.Optional[dt.datetime]
            Timestamp of last access to page structure

        page_content : typing.Optional[PageContent]
            Sections of page

        page_identifier : typing.Optional[PageIdentifier]

        page_settings : typing.Optional[PageSetting]
            Settings of page

        published : typing.Optional[int]
            Flag indicating if page is active to accept payments. `0` for false, `1` for true.

        receipt_content : typing.Optional[ReceiptContent]
            Sections of payment receipt

        subdomain : typing.Optional[Subdomain]
            Page identifier. Must be unique in platform.

        total_amount : typing.Optional[float]
            Total amount to pay in this page

        validation_code : typing.Optional[str]
            Base64 encoded image of CAPTCHA associated to this page load

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PayabliApiResponse00Responsedatanonobject
            Success

        Examples
        --------
        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.hosted_payment_pages.save_page(
            entry="8cfec329267",
            subdomain_="pay-your-fees-1",
        )
        """
        _response = self._raw_client.save_page(
            entry,
            subdomain_,
            additional_data=additional_data,
            credentials=credentials,
            last_access=last_access,
            page_content=page_content,
            page_identifier=page_identifier,
            page_settings=page_settings,
            published=published,
            receipt_content=receipt_content,
            subdomain=subdomain,
            total_amount=total_amount,
            validation_code=validation_code,
            request_options=request_options,
        )
        return _response.data


class AsyncHostedPaymentPagesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawHostedPaymentPagesClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawHostedPaymentPagesClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawHostedPaymentPagesClient
        """
        return self._raw_client

    async def load_page(
        self, entry: str, subdomain: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> PayabliPages:
        """
        Loads all of a payment page's details including `pageIdentifier` and `validationCode`. This endpoint requires an `application` API token.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        subdomain : str
            Payment page identifier. The subdomain value is the last part of the payment page URL. For example, in`https://paypages-sandbox.payabli.com/513823dc10/pay-your-fees-1`, the subdomain is `pay-your-fees-1`.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PayabliPages
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.hosted_payment_pages.load_page(
                entry="8cfec329267",
                subdomain="pay-your-fees-1",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.load_page(entry, subdomain, request_options=request_options)
        return _response.data

    async def new_page(
        self,
        entry: str,
        *,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        additional_data: typing.Optional[AdditionalData] = OMIT,
        credentials: typing.Optional[typing.Sequence[PayabliCredentials]] = OMIT,
        last_access: typing.Optional[dt.datetime] = OMIT,
        page_content: typing.Optional[PageContent] = OMIT,
        page_identifier: typing.Optional[PageIdentifier] = OMIT,
        page_settings: typing.Optional[PageSetting] = OMIT,
        published: typing.Optional[int] = OMIT,
        receipt_content: typing.Optional[ReceiptContent] = OMIT,
        subdomain: typing.Optional[Subdomain] = OMIT,
        total_amount: typing.Optional[float] = OMIT,
        validation_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PayabliApiResponse00Responsedatanonobject:
        """

        Creates a new payment page for a paypoint.
        Note: this operation doesn't create a new paypoint, just a payment page for an existing paypoint. Paypoints are created by the Payabli team when a boarding application is approved.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        idempotency_key : typing.Optional[IdempotencyKey]

        additional_data : typing.Optional[AdditionalData]

        credentials : typing.Optional[typing.Sequence[PayabliCredentials]]
            Array of credential objects with active services for the page

        last_access : typing.Optional[dt.datetime]
            Timestamp of last access to page structure

        page_content : typing.Optional[PageContent]
            Sections of page

        page_identifier : typing.Optional[PageIdentifier]

        page_settings : typing.Optional[PageSetting]
            Settings of page

        published : typing.Optional[int]
            Flag indicating if page is active to accept payments. `0` for false, `1` for true.

        receipt_content : typing.Optional[ReceiptContent]
            Sections of payment receipt

        subdomain : typing.Optional[Subdomain]
            Page identifier. Must be unique in platform.

        total_amount : typing.Optional[float]
            Total amount to pay in this page

        validation_code : typing.Optional[str]
            Base64 encoded image of CAPTCHA associated to this page load

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PayabliApiResponse00Responsedatanonobject
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.hosted_payment_pages.new_page(
                entry="8cfec329267",
                idempotency_key="6B29FC40-CA47-1067-B31D-00DD010662DA",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.new_page(
            entry,
            idempotency_key=idempotency_key,
            additional_data=additional_data,
            credentials=credentials,
            last_access=last_access,
            page_content=page_content,
            page_identifier=page_identifier,
            page_settings=page_settings,
            published=published,
            receipt_content=receipt_content,
            subdomain=subdomain,
            total_amount=total_amount,
            validation_code=validation_code,
            request_options=request_options,
        )
        return _response.data

    async def save_page(
        self,
        entry: str,
        subdomain_: str,
        *,
        additional_data: typing.Optional[AdditionalData] = OMIT,
        credentials: typing.Optional[typing.Sequence[PayabliCredentials]] = OMIT,
        last_access: typing.Optional[dt.datetime] = OMIT,
        page_content: typing.Optional[PageContent] = OMIT,
        page_identifier: typing.Optional[PageIdentifier] = OMIT,
        page_settings: typing.Optional[PageSetting] = OMIT,
        published: typing.Optional[int] = OMIT,
        receipt_content: typing.Optional[ReceiptContent] = OMIT,
        subdomain: typing.Optional[Subdomain] = OMIT,
        total_amount: typing.Optional[float] = OMIT,
        validation_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> PayabliApiResponse00Responsedatanonobject:
        """
        Updates a payment page in a paypoint.

        Parameters
        ----------
        entry : str
            The paypoint's entrypoint identifier. [Learn more](/api-reference/api-overview#entrypoint-vs-entry)

        subdomain_ : str
            Payment page identifier. The subdomain value is the last part of the payment page URL. For example, in`https://paypages-sandbox.payabli.com/513823dc10/pay-your-fees-1`, the subdomain is `pay-your-fees-1`.

        additional_data : typing.Optional[AdditionalData]

        credentials : typing.Optional[typing.Sequence[PayabliCredentials]]
            Array of credential objects with active services for the page

        last_access : typing.Optional[dt.datetime]
            Timestamp of last access to page structure

        page_content : typing.Optional[PageContent]
            Sections of page

        page_identifier : typing.Optional[PageIdentifier]

        page_settings : typing.Optional[PageSetting]
            Settings of page

        published : typing.Optional[int]
            Flag indicating if page is active to accept payments. `0` for false, `1` for true.

        receipt_content : typing.Optional[ReceiptContent]
            Sections of payment receipt

        subdomain : typing.Optional[Subdomain]
            Page identifier. Must be unique in platform.

        total_amount : typing.Optional[float]
            Total amount to pay in this page

        validation_code : typing.Optional[str]
            Base64 encoded image of CAPTCHA associated to this page load

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        PayabliApiResponse00Responsedatanonobject
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.hosted_payment_pages.save_page(
                entry="8cfec329267",
                subdomain_="pay-your-fees-1",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.save_page(
            entry,
            subdomain_,
            additional_data=additional_data,
            credentials=credentials,
            last_access=last_access,
            page_content=page_content,
            page_identifier=page_identifier,
            page_settings=page_settings,
            published=published,
            receipt_content=receipt_content,
            subdomain=subdomain,
            total_amount=total_amount,
            validation_code=validation_code,
            request_options=request_options,
        )
        return _response.data
