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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.include_total_count import IncludeTotalCount
from ..types.request_after_opaque_cursor import RequestAfterOpaqueCursor
from ..types.request_page_size import RequestPageSize
from ..types.uuid_ import Uuid
from ..types.webhook_create_response import WebhookCreateResponse
from ..types.webhook_response import WebhookResponse
from ..types.webhook_with_includes import WebhookWithIncludes
from ..types.webhook_with_includes_response import WebhookWithIncludesResponse
from ..types.webhooks_with_includes_response import WebhooksWithIncludesResponse
from .raw_client import AsyncRawWebhooksClient, RawWebhooksClient
from .types.webhook_create_params_data import WebhookCreateParamsData
from .types.webhook_update_params_data import WebhookUpdateParamsData

# 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 index(
        self,
        account_id: Uuid,
        workspace_id: Uuid,
        *,
        include: typing.Optional[typing.Literal["creator"]] = None,
        after: typing.Optional[RequestAfterOpaqueCursor] = None,
        page_size: typing.Optional[RequestPageSize] = None,
        include_total_count: typing.Optional[IncludeTotalCount] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[WebhookWithIncludes, WebhooksWithIncludesResponse]:
        """
        List webhooks for the given workspace. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        workspace_id : Uuid


        include : typing.Optional[typing.Literal["creator"]]


        after : typing.Optional[RequestAfterOpaqueCursor]
            Opaque Cursor query param for requests returning paginated results.
            <br/>
            NOTE: this value is auto-generated and included as part of links from a previous response. It is not intended to be human readable.

        page_size : typing.Optional[RequestPageSize]


        include_total_count : typing.Optional[IncludeTotalCount]


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

        Returns
        -------
        SyncPager[WebhookWithIncludes, WebhooksWithIncludesResponse]
            OK

        Examples
        --------
        from frameio import Frameio

        client = Frameio(
            token="YOUR_TOKEN",
        )
        response = client.webhooks.index(
            account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            workspace_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            after="<opaque_cursor>",
            page_size=10,
            include_total_count=False,
        )
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        return self._raw_client.index(
            account_id,
            workspace_id,
            include=include,
            after=after,
            page_size=page_size,
            include_total_count=include_total_count,
            request_options=request_options,
        )

    def create(
        self,
        account_id: Uuid,
        workspace_id: Uuid,
        *,
        data: WebhookCreateParamsData,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhookCreateResponse:
        """
        Creates a single webhook with secret.<br/><br/>Valid events:<p><code>
        file.created, file.deleted, file.ready, file.updated, file.upload.completed, file.versioned, file.copied, folder.created, folder.deleted, folder.updated, folder.copied, comment.completed, comment.created, comment.deleted, comment.uncompleted, comment.updated, customfield.created, customfield.updated, customfield.deleted, metadata.value.updated, project.created, project.deleted, project.updated, collection.created, collection.updated, collection.deleted, share.created, share.updated, share.deleted, share.viewed
        </code>
        </p>. <br>Rate Limits: 10 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        workspace_id : Uuid


        data : WebhookCreateParamsData

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

        Returns
        -------
        WebhookCreateResponse
            Created

        Examples
        --------
        from frameio import Frameio
        from frameio.webhooks import WebhookCreateParamsData

        client = Frameio(
            token="YOUR_TOKEN",
        )
        client.webhooks.create(
            account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            workspace_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            data=WebhookCreateParamsData(
                events=[
                    "file.created",
                    "file.deleted",
                    "file.ready",
                    "file.updated",
                    "file.upload.completed",
                    "file.versioned",
                    "file.copied",
                    "folder.created",
                    "folder.deleted",
                    "folder.updated",
                    "folder.copied",
                    "comment.completed",
                    "comment.created",
                    "comment.deleted",
                    "comment.uncompleted",
                    "comment.updated",
                    "customfield.created",
                    "customfield.updated",
                    "customfield.deleted",
                    "metadata.value.updated",
                    "project.created",
                    "project.deleted",
                    "project.updated",
                    "collection.created",
                    "collection.updated",
                    "collection.deleted",
                    "share.created",
                    "share.updated",
                    "share.deleted",
                    "share.viewed",
                ],
                name="New Webhook",
                url="https://url.example.com",
            ),
        )
        """
        _response = self._raw_client.create(account_id, workspace_id, data=data, request_options=request_options)
        return _response.data

    def show(
        self,
        account_id: Uuid,
        webhook_id: Uuid,
        *,
        include: typing.Optional[typing.Literal["creator"]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhookWithIncludesResponse:
        """
        Show webhook details. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        webhook_id : Uuid


        include : typing.Optional[typing.Literal["creator"]]


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

        Returns
        -------
        WebhookWithIncludesResponse
            OK

        Examples
        --------
        from frameio import Frameio

        client = Frameio(
            token="YOUR_TOKEN",
        )
        client.webhooks.show(
            account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            webhook_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
        )
        """
        _response = self._raw_client.show(account_id, webhook_id, include=include, request_options=request_options)
        return _response.data

    def delete(
        self, account_id: Uuid, webhook_id: Uuid, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a webhook. <br>Rate Limits: 60 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        webhook_id : Uuid


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

        Returns
        -------
        None

        Examples
        --------
        from frameio import Frameio

        client = Frameio(
            token="YOUR_TOKEN",
        )
        client.webhooks.delete(
            account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            webhook_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
        )
        """
        _response = self._raw_client.delete(account_id, webhook_id, request_options=request_options)
        return _response.data

    def update(
        self,
        account_id: Uuid,
        webhook_id: Uuid,
        *,
        data: WebhookUpdateParamsData,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhookResponse:
        """
        Update webhook details. <br>Rate Limits: 10 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        webhook_id : Uuid


        data : WebhookUpdateParamsData

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

        Returns
        -------
        WebhookResponse
            OK

        Examples
        --------
        from frameio import Frameio
        from frameio.webhooks import WebhookUpdateParamsData

        client = Frameio(
            token="YOUR_TOKEN",
        )
        client.webhooks.update(
            account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            webhook_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            data=WebhookUpdateParamsData(
                active=True,
                events=[
                    "file.created",
                    "file.deleted",
                    "file.ready",
                    "file.updated",
                    "file.upload.completed",
                    "file.versioned",
                    "file.copied",
                    "folder.created",
                    "folder.deleted",
                    "folder.updated",
                    "folder.copied",
                    "comment.completed",
                    "comment.created",
                    "comment.deleted",
                    "comment.uncompleted",
                    "comment.updated",
                    "customfield.created",
                    "customfield.updated",
                    "customfield.deleted",
                    "metadata.value.updated",
                    "project.created",
                    "project.deleted",
                    "project.updated",
                    "collection.created",
                    "collection.updated",
                    "collection.deleted",
                    "share.created",
                    "share.updated",
                    "share.deleted",
                    "share.viewed",
                ],
                name="Updated Webhook",
                url="https://url.example.com",
            ),
        )
        """
        _response = self._raw_client.update(account_id, webhook_id, data=data, 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 index(
        self,
        account_id: Uuid,
        workspace_id: Uuid,
        *,
        include: typing.Optional[typing.Literal["creator"]] = None,
        after: typing.Optional[RequestAfterOpaqueCursor] = None,
        page_size: typing.Optional[RequestPageSize] = None,
        include_total_count: typing.Optional[IncludeTotalCount] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[WebhookWithIncludes, WebhooksWithIncludesResponse]:
        """
        List webhooks for the given workspace. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        workspace_id : Uuid


        include : typing.Optional[typing.Literal["creator"]]


        after : typing.Optional[RequestAfterOpaqueCursor]
            Opaque Cursor query param for requests returning paginated results.
            <br/>
            NOTE: this value is auto-generated and included as part of links from a previous response. It is not intended to be human readable.

        page_size : typing.Optional[RequestPageSize]


        include_total_count : typing.Optional[IncludeTotalCount]


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

        Returns
        -------
        AsyncPager[WebhookWithIncludes, WebhooksWithIncludesResponse]
            OK

        Examples
        --------
        import asyncio

        from frameio import AsyncFrameio

        client = AsyncFrameio(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.webhooks.index(
                account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
                workspace_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
                after="<opaque_cursor>",
                page_size=10,
                include_total_count=False,
            )
            async for item in response:
                yield item

            # alternatively, you can paginate page-by-page
            async for page in response.iter_pages():
                yield page


        asyncio.run(main())
        """
        return await self._raw_client.index(
            account_id,
            workspace_id,
            include=include,
            after=after,
            page_size=page_size,
            include_total_count=include_total_count,
            request_options=request_options,
        )

    async def create(
        self,
        account_id: Uuid,
        workspace_id: Uuid,
        *,
        data: WebhookCreateParamsData,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhookCreateResponse:
        """
        Creates a single webhook with secret.<br/><br/>Valid events:<p><code>
        file.created, file.deleted, file.ready, file.updated, file.upload.completed, file.versioned, file.copied, folder.created, folder.deleted, folder.updated, folder.copied, comment.completed, comment.created, comment.deleted, comment.uncompleted, comment.updated, customfield.created, customfield.updated, customfield.deleted, metadata.value.updated, project.created, project.deleted, project.updated, collection.created, collection.updated, collection.deleted, share.created, share.updated, share.deleted, share.viewed
        </code>
        </p>. <br>Rate Limits: 10 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        workspace_id : Uuid


        data : WebhookCreateParamsData

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

        Returns
        -------
        WebhookCreateResponse
            Created

        Examples
        --------
        import asyncio

        from frameio import AsyncFrameio
        from frameio.webhooks import WebhookCreateParamsData

        client = AsyncFrameio(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.webhooks.create(
                account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
                workspace_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
                data=WebhookCreateParamsData(
                    events=[
                        "file.created",
                        "file.deleted",
                        "file.ready",
                        "file.updated",
                        "file.upload.completed",
                        "file.versioned",
                        "file.copied",
                        "folder.created",
                        "folder.deleted",
                        "folder.updated",
                        "folder.copied",
                        "comment.completed",
                        "comment.created",
                        "comment.deleted",
                        "comment.uncompleted",
                        "comment.updated",
                        "customfield.created",
                        "customfield.updated",
                        "customfield.deleted",
                        "metadata.value.updated",
                        "project.created",
                        "project.deleted",
                        "project.updated",
                        "collection.created",
                        "collection.updated",
                        "collection.deleted",
                        "share.created",
                        "share.updated",
                        "share.deleted",
                        "share.viewed",
                    ],
                    name="New Webhook",
                    url="https://url.example.com",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(account_id, workspace_id, data=data, request_options=request_options)
        return _response.data

    async def show(
        self,
        account_id: Uuid,
        webhook_id: Uuid,
        *,
        include: typing.Optional[typing.Literal["creator"]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhookWithIncludesResponse:
        """
        Show webhook details. <br>Rate Limits: 100 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        webhook_id : Uuid


        include : typing.Optional[typing.Literal["creator"]]


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

        Returns
        -------
        WebhookWithIncludesResponse
            OK

        Examples
        --------
        import asyncio

        from frameio import AsyncFrameio

        client = AsyncFrameio(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.webhooks.show(
                account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
                webhook_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.show(
            account_id, webhook_id, include=include, request_options=request_options
        )
        return _response.data

    async def delete(
        self, account_id: Uuid, webhook_id: Uuid, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a webhook. <br>Rate Limits: 60 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        webhook_id : Uuid


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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from frameio import AsyncFrameio

        client = AsyncFrameio(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.webhooks.delete(
                account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
                webhook_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(account_id, webhook_id, request_options=request_options)
        return _response.data

    async def update(
        self,
        account_id: Uuid,
        webhook_id: Uuid,
        *,
        data: WebhookUpdateParamsData,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> WebhookResponse:
        """
        Update webhook details. <br>Rate Limits: 10 calls per 1.00 minute(s) per account_user

        Parameters
        ----------
        account_id : Uuid


        webhook_id : Uuid


        data : WebhookUpdateParamsData

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

        Returns
        -------
        WebhookResponse
            OK

        Examples
        --------
        import asyncio

        from frameio import AsyncFrameio
        from frameio.webhooks import WebhookUpdateParamsData

        client = AsyncFrameio(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.webhooks.update(
                account_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
                webhook_id="b2702c44-c6da-4bb6-8bbd-be6e547ccf1b",
                data=WebhookUpdateParamsData(
                    active=True,
                    events=[
                        "file.created",
                        "file.deleted",
                        "file.ready",
                        "file.updated",
                        "file.upload.completed",
                        "file.versioned",
                        "file.copied",
                        "folder.created",
                        "folder.deleted",
                        "folder.updated",
                        "folder.copied",
                        "comment.completed",
                        "comment.created",
                        "comment.deleted",
                        "comment.uncompleted",
                        "comment.updated",
                        "customfield.created",
                        "customfield.updated",
                        "customfield.deleted",
                        "metadata.value.updated",
                        "project.created",
                        "project.deleted",
                        "project.updated",
                        "collection.created",
                        "collection.updated",
                        "collection.deleted",
                        "share.created",
                        "share.updated",
                        "share.deleted",
                        "share.viewed",
                    ],
                    name="Updated Webhook",
                    url="https://url.example.com",
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(account_id, webhook_id, data=data, request_options=request_options)
        return _response.data
