# 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.custom_headers_object_request_body import CustomHeadersObjectRequestBody
from ..types.webhooks_get_webhook_response_body import WebhooksGetWebhookResponseBody
from ..types.webhooks_list_webhooks_response_body import WebhooksListWebhooksResponseBody
from ..types.webhooks_patch_webhook_response_body import WebhooksPatchWebhookResponseBody
from ..types.webhooks_post_webhooks_response_body import WebhooksPostWebhooksResponseBody
from .raw_client import AsyncRawWebhooksClient, RawWebhooksClient
from .types.webhooks_patch_webhook_request_body_version import WebhooksPatchWebhookRequestBodyVersion
from .types.webhooks_post_webhooks_request_body_event_types_item import WebhooksPostWebhooksRequestBodyEventTypesItem
from .types.webhooks_post_webhooks_request_body_version import WebhooksPostWebhooksRequestBodyVersion

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


class WebhooksClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawWebhooksClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawWebhooksClient
        """
        return self._raw_client

    def list_webhooks(
        self,
        *,
        ids: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhooksListWebhooksResponseBody:
        """
        List all webhooks belonging to a specific org.

         <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 Webhooks** 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
        ----------
        ids : typing.Optional[str]
             A filter on the data based on this comma-separated list of webhook IDs. Example: `ids=49412323223,49412329928`

        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        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
        -------
        WebhooksListWebhooksResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.webhooks.list_webhooks()
        """
        _response = self._raw_client.list_webhooks(ids=ids, limit=limit, after=after, request_options=request_options)
        return _response.data

    def post_webhooks(
        self,
        *,
        name: str,
        url: str,
        custom_headers: typing.Optional[typing.Sequence[CustomHeadersObjectRequestBody]] = OMIT,
        event_types: typing.Optional[typing.Sequence[WebhooksPostWebhooksRequestBodyEventTypesItem]] = OMIT,
        version: typing.Optional[WebhooksPostWebhooksRequestBodyVersion] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhooksPostWebhooksResponseBody:
        """
        Create a webhook

         <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 Webhooks** 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
        ----------
        name : str
            The  name of the webhook. This will appear in both Samsara’s cloud dashboard and the API. It can be set or updated through the Samsara Dashboard or through the API at any time.

        url : str
            The url of the webhook. This will appear in both Samsara’s cloud dashboard and the API. It can be set or updated through the Samsara Dashboard or through the API at any time.

        custom_headers : typing.Optional[typing.Sequence[CustomHeadersObjectRequestBody]]
            The list of custom headers that users can include with their request

        event_types : typing.Optional[typing.Sequence[WebhooksPostWebhooksRequestBodyEventTypesItem]]
            [beta] The list of event types associated with a particular event type

        version : typing.Optional[WebhooksPostWebhooksRequestBodyVersion]
            The version of the webhook.  Valid values: `2018-01-01`, `2021-06-09`, `2022-09-13`, `2024-02-27`

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

        Returns
        -------
        WebhooksPostWebhooksResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.webhooks.post_webhooks(
            name="Webhook-123",
            url="https://www.Webhook-123.com/webhook/listener",
        )
        """
        _response = self._raw_client.post_webhooks(
            name=name,
            url=url,
            custom_headers=custom_headers,
            event_types=event_types,
            version=version,
            request_options=request_options,
        )
        return _response.data

    def get_webhook(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> WebhooksGetWebhookResponseBody:
        """
        Retrieve a webhook with given ID.

         <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 Webhooks** 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
            ID of the webhook. This is the Samsara-specified ID.

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

        Returns
        -------
        WebhooksGetWebhookResponseBody
            OK response.

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

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

    def delete_webhook(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete a webhook with the given ID.

         <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 Webhooks** 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
            Unique identifier for the webhook to delete.

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

        Returns
        -------
        None

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

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

    def patch_webhook(
        self,
        id: str,
        *,
        custom_headers: typing.Optional[typing.Sequence[CustomHeadersObjectRequestBody]] = OMIT,
        name: typing.Optional[str] = OMIT,
        url: typing.Optional[str] = OMIT,
        version: typing.Optional[WebhooksPatchWebhookRequestBodyVersion] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhooksPatchWebhookResponseBody:
        """
        Update a specific webhook's information.  **Note** this implementation of patch uses [the JSON merge patch](https://tools.ietf.org/html/rfc7396) proposed standard.
         This means that any fields included in the patch request will _overwrite_ fields which exist on the target resource.
         For arrays, this means any array included in the request will _replace_ the array that exists at the specified path, it will not _add_ to the existing array

         <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 Webhooks** 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
            Unique identifier for the webhook to update.

        custom_headers : typing.Optional[typing.Sequence[CustomHeadersObjectRequestBody]]
            The list of custom headers that users can include with their request

        name : typing.Optional[str]
            The  name of the webhook. This will appear in both Samsara’s cloud dashboard and the API. It can be set or updated through the Samsara Dashboard or through the API at any time.

        url : typing.Optional[str]
            The url of the webhook. This will appear in both Samsara’s cloud dashboard and the API. It can be set or updated through the Samsara Dashboard or through the API at any time.

        version : typing.Optional[WebhooksPatchWebhookRequestBodyVersion]
            The version of the webhook.  Valid values: `2018-01-01`, `2021-06-09`, `2022-09-13`, `2024-02-27`

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

        Returns
        -------
        WebhooksPatchWebhookResponseBody
            OK response.

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

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.webhooks.patch_webhook(
            id="id",
        )
        """
        _response = self._raw_client.patch_webhook(
            id, custom_headers=custom_headers, name=name, url=url, version=version, request_options=request_options
        )
        return _response.data


class AsyncWebhooksClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawWebhooksClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawWebhooksClient
        """
        return self._raw_client

    async def list_webhooks(
        self,
        *,
        ids: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhooksListWebhooksResponseBody:
        """
        List all webhooks belonging to a specific org.

         <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 Webhooks** 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
        ----------
        ids : typing.Optional[str]
             A filter on the data based on this comma-separated list of webhook IDs. Example: `ids=49412323223,49412329928`

        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        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
        -------
        WebhooksListWebhooksResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.webhooks.list_webhooks()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_webhooks(
            ids=ids, limit=limit, after=after, request_options=request_options
        )
        return _response.data

    async def post_webhooks(
        self,
        *,
        name: str,
        url: str,
        custom_headers: typing.Optional[typing.Sequence[CustomHeadersObjectRequestBody]] = OMIT,
        event_types: typing.Optional[typing.Sequence[WebhooksPostWebhooksRequestBodyEventTypesItem]] = OMIT,
        version: typing.Optional[WebhooksPostWebhooksRequestBodyVersion] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhooksPostWebhooksResponseBody:
        """
        Create a webhook

         <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 Webhooks** 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
        ----------
        name : str
            The  name of the webhook. This will appear in both Samsara’s cloud dashboard and the API. It can be set or updated through the Samsara Dashboard or through the API at any time.

        url : str
            The url of the webhook. This will appear in both Samsara’s cloud dashboard and the API. It can be set or updated through the Samsara Dashboard or through the API at any time.

        custom_headers : typing.Optional[typing.Sequence[CustomHeadersObjectRequestBody]]
            The list of custom headers that users can include with their request

        event_types : typing.Optional[typing.Sequence[WebhooksPostWebhooksRequestBodyEventTypesItem]]
            [beta] The list of event types associated with a particular event type

        version : typing.Optional[WebhooksPostWebhooksRequestBodyVersion]
            The version of the webhook.  Valid values: `2018-01-01`, `2021-06-09`, `2022-09-13`, `2024-02-27`

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

        Returns
        -------
        WebhooksPostWebhooksResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.webhooks.post_webhooks(
                name="Webhook-123",
                url="https://www.Webhook-123.com/webhook/listener",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.post_webhooks(
            name=name,
            url=url,
            custom_headers=custom_headers,
            event_types=event_types,
            version=version,
            request_options=request_options,
        )
        return _response.data

    async def get_webhook(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> WebhooksGetWebhookResponseBody:
        """
        Retrieve a webhook with given ID.

         <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 Webhooks** 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
            ID of the webhook. This is the Samsara-specified ID.

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

        Returns
        -------
        WebhooksGetWebhookResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


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


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

    async def delete_webhook(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Delete a webhook with the given ID.

         <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 Webhooks** 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
            Unique identifier for the webhook to delete.

        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.webhooks.delete_webhook(
                id="id",
            )


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

    async def patch_webhook(
        self,
        id: str,
        *,
        custom_headers: typing.Optional[typing.Sequence[CustomHeadersObjectRequestBody]] = OMIT,
        name: typing.Optional[str] = OMIT,
        url: typing.Optional[str] = OMIT,
        version: typing.Optional[WebhooksPatchWebhookRequestBodyVersion] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhooksPatchWebhookResponseBody:
        """
        Update a specific webhook's information.  **Note** this implementation of patch uses [the JSON merge patch](https://tools.ietf.org/html/rfc7396) proposed standard.
         This means that any fields included in the patch request will _overwrite_ fields which exist on the target resource.
         For arrays, this means any array included in the request will _replace_ the array that exists at the specified path, it will not _add_ to the existing array

         <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 Webhooks** 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
            Unique identifier for the webhook to update.

        custom_headers : typing.Optional[typing.Sequence[CustomHeadersObjectRequestBody]]
            The list of custom headers that users can include with their request

        name : typing.Optional[str]
            The  name of the webhook. This will appear in both Samsara’s cloud dashboard and the API. It can be set or updated through the Samsara Dashboard or through the API at any time.

        url : typing.Optional[str]
            The url of the webhook. This will appear in both Samsara’s cloud dashboard and the API. It can be set or updated through the Samsara Dashboard or through the API at any time.

        version : typing.Optional[WebhooksPatchWebhookRequestBodyVersion]
            The version of the webhook.  Valid values: `2018-01-01`, `2021-06-09`, `2022-09-13`, `2024-02-27`

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

        Returns
        -------
        WebhooksPatchWebhookResponseBody
            OK response.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


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


        asyncio.run(main())
        """
        _response = await self._raw_client.patch_webhook(
            id, custom_headers=custom_headers, name=name, url=url, version=version, request_options=request_options
        )
        return _response.data
