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

import datetime as dt
import typing
import uuid

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.pagesize import Pagesize
from .raw_client import AsyncRawNotificationlogsClient, RawNotificationlogsClient
from .types.bulk_retry_request import BulkRetryRequest
from .types.notification_log import NotificationLog
from .types.notification_log_detail import NotificationLogDetail

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


class NotificationlogsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawNotificationlogsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawNotificationlogsClient
        """
        return self._raw_client

    def search_notification_logs(
        self,
        *,
        start_date: dt.datetime,
        end_date: dt.datetime,
        page_size: typing.Optional[Pagesize] = None,
        skip: typing.Optional[int] = None,
        notification_event: typing.Optional[str] = OMIT,
        succeeded: typing.Optional[bool] = OMIT,
        org_id: typing.Optional[int] = OMIT,
        paypoint_id: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[NotificationLog]:
        """
        Search notification logs with filtering and pagination.
          - Start date and end date cannot be more than 30 days apart
          - Either `orgId` or `paypointId` must be provided

        This endpoint requires the `notifications_create` OR `notifications_read` permission.

        Parameters
        ----------
        start_date : dt.datetime
            The start date for the search.

        end_date : dt.datetime
            The end date for the search.

        page_size : typing.Optional[Pagesize]

        skip : typing.Optional[int]
            The number of records to skip before starting to collect the result set.

        notification_event : typing.Optional[str]
            The type of notification event to filter by.

        succeeded : typing.Optional[bool]
            Indicates whether the notification was successful.

        org_id : typing.Optional[int]
            The ID of the organization to filter by.

        paypoint_id : typing.Optional[int]
            The ID of the paypoint to filter by.

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

        Returns
        -------
        typing.List[NotificationLog]

        Examples
        --------
        import datetime

        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.notificationlogs.search_notification_logs(
            page_size=20,
            start_date=datetime.datetime.fromisoformat(
                "2024-01-01 00:00:00+00:00",
            ),
            end_date=datetime.datetime.fromisoformat(
                "2024-01-31 23:59:59+00:00",
            ),
            org_id=12345,
            notification_event="ActivatedMerchant",
            succeeded=True,
        )
        """
        _response = self._raw_client.search_notification_logs(
            start_date=start_date,
            end_date=end_date,
            page_size=page_size,
            skip=skip,
            notification_event=notification_event,
            succeeded=succeeded,
            org_id=org_id,
            paypoint_id=paypoint_id,
            request_options=request_options,
        )
        return _response.data

    def get_notification_log(
        self, uuid_: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> NotificationLogDetail:
        """
        Get detailed information for a specific notification log entry.
        This endpoint requires the `notifications_create` OR `notifications_read` permission.

        Parameters
        ----------
        uuid_ : uuid.UUID
            The notification log entry.

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

        Returns
        -------
        NotificationLogDetail

        Examples
        --------
        import uuid

        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.notificationlogs.get_notification_log(
            uuid_=uuid.UUID(
                "550e8400-e29b-41d4-a716-446655440000",
            ),
        )
        """
        _response = self._raw_client.get_notification_log(uuid_, request_options=request_options)
        return _response.data

    def retry_notification_log(
        self, uuid_: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> NotificationLogDetail:
        """
        Retry sending a specific notification.

        **Permissions:** notifications_create

        Parameters
        ----------
        uuid_ : uuid.UUID
            Unique id

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

        Returns
        -------
        NotificationLogDetail

        Examples
        --------
        import uuid

        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.notificationlogs.retry_notification_log(
            uuid_=uuid.UUID(
                "550e8400-e29b-41d4-a716-446655440000",
            ),
        )
        """
        _response = self._raw_client.retry_notification_log(uuid_, request_options=request_options)
        return _response.data

    def bulk_retry_notification_logs(
        self, *, request: BulkRetryRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Retry sending multiple notifications (maximum 50 IDs).
        This is an async process, so use the search endpoint again to check the notification status.

        This endpoint requires the `notifications_create` permission.

        Parameters
        ----------
        request : BulkRetryRequest

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

        Returns
        -------
        None

        Examples
        --------
        import uuid

        from payabli import payabli

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.notificationlogs.bulk_retry_notification_logs(
            request=[
                uuid.UUID(
                    "550e8400-e29b-41d4-a716-446655440000",
                ),
                uuid.UUID(
                    "550e8400-e29b-41d4-a716-446655440001",
                ),
                uuid.UUID(
                    "550e8400-e29b-41d4-a716-446655440002",
                ),
            ],
        )
        """
        _response = self._raw_client.bulk_retry_notification_logs(request=request, request_options=request_options)
        return _response.data


class AsyncNotificationlogsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawNotificationlogsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawNotificationlogsClient
        """
        return self._raw_client

    async def search_notification_logs(
        self,
        *,
        start_date: dt.datetime,
        end_date: dt.datetime,
        page_size: typing.Optional[Pagesize] = None,
        skip: typing.Optional[int] = None,
        notification_event: typing.Optional[str] = OMIT,
        succeeded: typing.Optional[bool] = OMIT,
        org_id: typing.Optional[int] = OMIT,
        paypoint_id: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[NotificationLog]:
        """
        Search notification logs with filtering and pagination.
          - Start date and end date cannot be more than 30 days apart
          - Either `orgId` or `paypointId` must be provided

        This endpoint requires the `notifications_create` OR `notifications_read` permission.

        Parameters
        ----------
        start_date : dt.datetime
            The start date for the search.

        end_date : dt.datetime
            The end date for the search.

        page_size : typing.Optional[Pagesize]

        skip : typing.Optional[int]
            The number of records to skip before starting to collect the result set.

        notification_event : typing.Optional[str]
            The type of notification event to filter by.

        succeeded : typing.Optional[bool]
            Indicates whether the notification was successful.

        org_id : typing.Optional[int]
            The ID of the organization to filter by.

        paypoint_id : typing.Optional[int]
            The ID of the paypoint to filter by.

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

        Returns
        -------
        typing.List[NotificationLog]

        Examples
        --------
        import asyncio
        import datetime

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.notificationlogs.search_notification_logs(
                page_size=20,
                start_date=datetime.datetime.fromisoformat(
                    "2024-01-01 00:00:00+00:00",
                ),
                end_date=datetime.datetime.fromisoformat(
                    "2024-01-31 23:59:59+00:00",
                ),
                org_id=12345,
                notification_event="ActivatedMerchant",
                succeeded=True,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.search_notification_logs(
            start_date=start_date,
            end_date=end_date,
            page_size=page_size,
            skip=skip,
            notification_event=notification_event,
            succeeded=succeeded,
            org_id=org_id,
            paypoint_id=paypoint_id,
            request_options=request_options,
        )
        return _response.data

    async def get_notification_log(
        self, uuid_: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> NotificationLogDetail:
        """
        Get detailed information for a specific notification log entry.
        This endpoint requires the `notifications_create` OR `notifications_read` permission.

        Parameters
        ----------
        uuid_ : uuid.UUID
            The notification log entry.

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

        Returns
        -------
        NotificationLogDetail

        Examples
        --------
        import asyncio
        import uuid

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.notificationlogs.get_notification_log(
                uuid_=uuid.UUID(
                    "550e8400-e29b-41d4-a716-446655440000",
                ),
            )


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

    async def retry_notification_log(
        self, uuid_: uuid.UUID, *, request_options: typing.Optional[RequestOptions] = None
    ) -> NotificationLogDetail:
        """
        Retry sending a specific notification.

        **Permissions:** notifications_create

        Parameters
        ----------
        uuid_ : uuid.UUID
            Unique id

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

        Returns
        -------
        NotificationLogDetail

        Examples
        --------
        import asyncio
        import uuid

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.notificationlogs.retry_notification_log(
                uuid_=uuid.UUID(
                    "550e8400-e29b-41d4-a716-446655440000",
                ),
            )


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

    async def bulk_retry_notification_logs(
        self, *, request: BulkRetryRequest, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Retry sending multiple notifications (maximum 50 IDs).
        This is an async process, so use the search endpoint again to check the notification status.

        This endpoint requires the `notifications_create` permission.

        Parameters
        ----------
        request : BulkRetryRequest

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio
        import uuid

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.notificationlogs.bulk_retry_notification_logs(
                request=[
                    uuid.UUID(
                        "550e8400-e29b-41d4-a716-446655440000",
                    ),
                    uuid.UUID(
                        "550e8400-e29b-41d4-a716-446655440001",
                    ),
                    uuid.UUID(
                        "550e8400-e29b-41d4-a716-446655440002",
                    ),
                ],
            )


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