# 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.gateways_get_gateways_response_body import GatewaysGetGatewaysResponseBody
from ..types.gateways_post_gateway_response_body import GatewaysPostGatewayResponseBody
from .raw_client import AsyncRawGatewaysClient, RawGatewaysClient

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


class GatewaysClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawGatewaysClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawGatewaysClient
        """
        return self._raw_client

    def get_gateways(
        self,
        *,
        models: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GatewaysGetGatewaysResponseBody:
        """
        List all gateways

         <b>Rate limit:</b> 5 requests/sec (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Read Gateways** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        models : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter by a comma separated list of gateway models.

        after : typing.Optional[str]
             If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

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

        Returns
        -------
        GatewaysGetGatewaysResponseBody
            OK response.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.gateways.get_gateways()
        """
        _response = self._raw_client.get_gateways(models=models, after=after, request_options=request_options)
        return _response.data

    def post_gateway(
        self, *, serial: str, request_options: typing.Optional[RequestOptions] = None
    ) -> GatewaysPostGatewayResponseBody:
        """
        Activate a new gateway. To activate a device and associate it with your organization, enter its serial number. Each device's serial number can also be found on its label or packaging, or from your order confirmation email. A Not Found error could mean that the serial was not found or it has already been activated

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Gateways** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        serial : str
            Gateway serial number

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

        Returns
        -------
        GatewaysPostGatewayResponseBody
            OK response.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.gateways.post_gateway(
            serial="GFRV-43N-VGX",
        )
        """
        _response = self._raw_client.post_gateway(serial=serial, request_options=request_options)
        return _response.data

    def delete_gateway(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Deactivate a gateway

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Gateways** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        id : str
            Gateway serial number

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

        Returns
        -------
        None

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.gateways.delete_gateway(
            id="id",
        )
        """
        _response = self._raw_client.delete_gateway(id, request_options=request_options)
        return _response.data


class AsyncGatewaysClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawGatewaysClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawGatewaysClient
        """
        return self._raw_client

    async def get_gateways(
        self,
        *,
        models: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GatewaysGetGatewaysResponseBody:
        """
        List all gateways

         <b>Rate limit:</b> 5 requests/sec (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Read Gateways** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        models : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Filter by a comma separated list of gateway models.

        after : typing.Optional[str]
             If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

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

        Returns
        -------
        GatewaysGetGatewaysResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.gateways.get_gateways()


        asyncio.run(main())
        """
        _response = await self._raw_client.get_gateways(models=models, after=after, request_options=request_options)
        return _response.data

    async def post_gateway(
        self, *, serial: str, request_options: typing.Optional[RequestOptions] = None
    ) -> GatewaysPostGatewayResponseBody:
        """
        Activate a new gateway. To activate a device and associate it with your organization, enter its serial number. Each device's serial number can also be found on its label or packaging, or from your order confirmation email. A Not Found error could mean that the serial was not found or it has already been activated

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Gateways** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        serial : str
            Gateway serial number

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

        Returns
        -------
        GatewaysPostGatewayResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.gateways.post_gateway(
                serial="GFRV-43N-VGX",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.post_gateway(serial=serial, request_options=request_options)
        return _response.data

    async def delete_gateway(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Deactivate a gateway

         <b>Rate limit:</b> 100 requests/min (learn more about rate limits <a href="https://developers.samsara.com/docs/rate-limits" target="_blank">here</a>).

        To use this endpoint, select **Write Gateways** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>


         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        Parameters
        ----------
        id : str
            Gateway serial number

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.gateways.delete_gateway(
                id="id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_gateway(id, request_options=request_options)
        return _response.data
