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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.cloud_query_api_response import CloudQueryApiResponse
from ..types.idempotency_key import IdempotencyKey
from .raw_client import AsyncRawCloudClient, RawCloudClient
from .types.add_device_response import AddDeviceResponse
from .types.remove_device_response import RemoveDeviceResponse

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


class CloudClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCloudClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCloudClient
        """
        return self._raw_client

    def add_device(
        self,
        entry: str,
        *,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        description: typing.Optional[str] = OMIT,
        registration_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AddDeviceResponse:
        """
        Register a cloud device to an entrypoint. See [Devices Quickstart](/developers/developer-guides/devices-quickstart#devices-quickstart) for a complete guide.

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

        idempotency_key : typing.Optional[IdempotencyKey]

        description : typing.Optional[str]
            Description or name for the device. This can be anything, but Payabli recommends entering the name of the paypoint, or some other easy to identify descriptor. If you have several devices for one paypoint, you can give them descriptions like "Cashier 1" and "Cashier 2", or "Front Desk" and "Back Office"

        registration_code : typing.Optional[str]
            The device registration code or serial number, depending on the model.

            - Ingenico devices: This is the activation code that's displayed on the device screen during setup.

            - PAX A920 device: This code is the serial number on the back of the device.

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

        Returns
        -------
        AddDeviceResponse
            Success

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

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.cloud.add_device(
            entry="8cfec329267",
            registration_code="YS7DS5",
            description="Front Desk POS",
        )
        """
        _response = self._raw_client.add_device(
            entry,
            idempotency_key=idempotency_key,
            description=description,
            registration_code=registration_code,
            request_options=request_options,
        )
        return _response.data

    def history_device(
        self, device_id: str, entry: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CloudQueryApiResponse:
        """
        Retrieve the registration history for a device.

        Parameters
        ----------
        device_id : str
            ID of the cloud device.

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

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

        Returns
        -------
        CloudQueryApiResponse
            Success

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

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.cloud.history_device(
            device_id="WXGDWB",
            entry="8cfec329267",
        )
        """
        _response = self._raw_client.history_device(device_id, entry, request_options=request_options)
        return _response.data

    def list_device(
        self,
        entry: str,
        *,
        force_refresh: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CloudQueryApiResponse:
        """
        Get a list of cloud devices registered to an entrypoint.

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

        force_refresh : typing.Optional[bool]
            When `true`, the request retrieves an updated list of devices from the processor instead of returning a cached list of devices.

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

        Returns
        -------
        CloudQueryApiResponse
            Success

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

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.cloud.list_device(
            entry="8cfec329267",
        )
        """
        _response = self._raw_client.list_device(entry, force_refresh=force_refresh, request_options=request_options)
        return _response.data

    def remove_device(
        self, device_id: str, entry: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RemoveDeviceResponse:
        """
        Remove a cloud device from an entrypoint.

        Parameters
        ----------
        device_id : str
            ID of the cloud device.

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

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

        Returns
        -------
        RemoveDeviceResponse
            Success

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

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.cloud.remove_device(
            device_id="6c361c7d-674c-44cc-b790-382b75d1xxx",
            entry="8cfec329267",
        )
        """
        _response = self._raw_client.remove_device(device_id, entry, request_options=request_options)
        return _response.data


class AsyncCloudClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCloudClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCloudClient
        """
        return self._raw_client

    async def add_device(
        self,
        entry: str,
        *,
        idempotency_key: typing.Optional[IdempotencyKey] = None,
        description: typing.Optional[str] = OMIT,
        registration_code: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AddDeviceResponse:
        """
        Register a cloud device to an entrypoint. See [Devices Quickstart](/developers/developer-guides/devices-quickstart#devices-quickstart) for a complete guide.

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

        idempotency_key : typing.Optional[IdempotencyKey]

        description : typing.Optional[str]
            Description or name for the device. This can be anything, but Payabli recommends entering the name of the paypoint, or some other easy to identify descriptor. If you have several devices for one paypoint, you can give them descriptions like "Cashier 1" and "Cashier 2", or "Front Desk" and "Back Office"

        registration_code : typing.Optional[str]
            The device registration code or serial number, depending on the model.

            - Ingenico devices: This is the activation code that's displayed on the device screen during setup.

            - PAX A920 device: This code is the serial number on the back of the device.

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

        Returns
        -------
        AddDeviceResponse
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.cloud.add_device(
                entry="8cfec329267",
                registration_code="YS7DS5",
                description="Front Desk POS",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_device(
            entry,
            idempotency_key=idempotency_key,
            description=description,
            registration_code=registration_code,
            request_options=request_options,
        )
        return _response.data

    async def history_device(
        self, device_id: str, entry: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> CloudQueryApiResponse:
        """
        Retrieve the registration history for a device.

        Parameters
        ----------
        device_id : str
            ID of the cloud device.

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

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

        Returns
        -------
        CloudQueryApiResponse
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.cloud.history_device(
                device_id="WXGDWB",
                entry="8cfec329267",
            )


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

    async def list_device(
        self,
        entry: str,
        *,
        force_refresh: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CloudQueryApiResponse:
        """
        Get a list of cloud devices registered to an entrypoint.

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

        force_refresh : typing.Optional[bool]
            When `true`, the request retrieves an updated list of devices from the processor instead of returning a cached list of devices.

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

        Returns
        -------
        CloudQueryApiResponse
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.cloud.list_device(
                entry="8cfec329267",
            )


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

    async def remove_device(
        self, device_id: str, entry: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RemoveDeviceResponse:
        """
        Remove a cloud device from an entrypoint.

        Parameters
        ----------
        device_id : str
            ID of the cloud device.

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

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

        Returns
        -------
        RemoveDeviceResponse
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.cloud.remove_device(
                device_id="6c361c7d-674c-44cc-b790-382b75d1xxx",
                entry="8cfec329267",
            )


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