# 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 .raw_client import AsyncRawStatisticClient, RawStatisticClient
from .types.stat_basic_query_record import StatBasicQueryRecord
from .types.statistics_vendor_query_record import StatisticsVendorQueryRecord
from .types.subscription_stats_query_record import SubscriptionStatsQueryRecord


class StatisticClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawStatisticClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawStatisticClient
        """
        return self._raw_client

    def basic_stats(
        self,
        entry_id: int,
        freq: str,
        level: int,
        mode: str,
        *,
        end_date: typing.Optional[str] = None,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        start_date: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[StatBasicQueryRecord]:
        """
        Retrieves the basic statistics for an organization or a paypoint, for a given time period, grouped by a particular frequency.

        Parameters
        ----------
        entry_id : int
            Identifier in Payabli for the entity.

        freq : str
            Frequency to group series. Allowed values:

            - `m` - monthly
            - `w` - weekly
            - `d` - daily
            - `h` - hourly

            For example, `w` groups the results by week.

        level : int
            The entry level for the request:
              - 0 for Organization
              - 2 for Paypoint

        mode : str
            Mode for the request. Allowed values:

            - `custom` - Allows you to set a custom date range
            - `ytd` - Year To Date
            - `mtd` - Month To Date
            - `wtd` - Week To Date
            - `today` - All current day
            - `m12` - Last 12 months
            - `d30` - Last 30 days
            - `h24` - Last 24 hours
            - `lasty` - Last Year
            - `lastm` - Last Month
            - `lastw` - Last Week
            - `yesterday` - Last Day


        end_date : typing.Optional[str]
            Used with `custom` mode. The end date for the range.
            Valid formats:
              - YYYY-mm-dd
              - YYYY/mm/dd
              - mm-dd-YYYY
              - mm/dd/YYYY

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            List of parameters.

        start_date : typing.Optional[str]
            Used with `custom` mode. The start date for the range.
            Valid formats:
               - YYYY-mm-dd
               - YYYY/mm/dd
               -  mm-dd-YYYY
               - mm/dd/YYYY

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

        Returns
        -------
        typing.List[StatBasicQueryRecord]
            Success

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

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.statistic.basic_stats(
            entry_id=1000000,
            freq="m",
            level=1,
            mode="ytd",
            end_date="2023-05-23",
            start_date="2023-03-23",
        )
        """
        _response = self._raw_client.basic_stats(
            entry_id,
            freq,
            level,
            mode,
            end_date=end_date,
            parameters=parameters,
            start_date=start_date,
            request_options=request_options,
        )
        return _response.data

    def customer_basic_stats(
        self,
        customer_id: int,
        freq: str,
        mode: str,
        *,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[SubscriptionStatsQueryRecord]:
        """
        Retrieves the basic statistics for a customer for a specific time period, grouped by a selected frequency.

        Parameters
        ----------
        customer_id : int
            Payabli-generated customer ID. Maps to "Customer ID" column in PartnerHub.

        freq : str
            Frequency to group series. Allowed values:

            - `m` - monthly
            - `w` - weekly
            - `d` - daily
            - `h` - hourly

            For example, `w` groups the results by week.

        mode : str
            Mode for request. Allowed values:

            - `ytd` - Year To Date
            - `mtd` - Month To Date
            - `wtd` - Week To Date
            - `today` - All current day
            - `m12` - Last 12 months
            - `d30` - Last 30 days
            - `h24` - Last 24 hours
            - `lasty` - Last Year
            - `lastm` - Last Month
            - `lastw` - Last Week
            - `yesterday` - Last Day

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            List of parameters.

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

        Returns
        -------
        typing.List[SubscriptionStatsQueryRecord]
            Success

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

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.statistic.customer_basic_stats(
            customer_id=998,
            freq="m",
            mode="ytd",
        )
        """
        _response = self._raw_client.customer_basic_stats(
            customer_id, freq, mode, parameters=parameters, request_options=request_options
        )
        return _response.data

    def sub_stats(
        self,
        entry_id: int,
        interval: str,
        level: int,
        *,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[StatBasicQueryRecord]:
        """
        Retrieves the subscription statistics for a given interval for a paypoint or organization.

        Parameters
        ----------
        entry_id : int
            Identifier in Payabli for the entity.

        interval : str
            Interval to get the data. Allowed values:

            - `all` - all intervals
            - `30` - 1-30 days
            - `60` - 31-60 days
            - `90` - 61-90 days
            - `plus` - +90 days

        level : int
            The entry level for the request:
              - 0 for Organization
              - 2 for Paypoint

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            List of parameters

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

        Returns
        -------
        typing.List[StatBasicQueryRecord]
            Success

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

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.statistic.sub_stats(
            entry_id=1000000,
            interval="30",
            level=1,
        )
        """
        _response = self._raw_client.sub_stats(
            entry_id, interval, level, parameters=parameters, request_options=request_options
        )
        return _response.data

    def vendor_basic_stats(
        self,
        freq: str,
        id_vendor: int,
        mode: str,
        *,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[StatisticsVendorQueryRecord]:
        """
        Retrieve the basic statistics about a vendor for a given time period, grouped by frequency.

        Parameters
        ----------
        freq : str
            Frequency to group series. Allowed values:

            - `m` - monthly
            - `w` - weekly
            - `d` - daily
            - `h` - hourly

            For example, `w` groups the results by week.

        id_vendor : int
            Vendor ID.

        mode : str
            Mode for request. Allowed values:

            - `ytd` - Year To Date
            - `mtd` - Month To Date
            - `wtd` - Week To Date
            - `today` - All current day
            - `m12` - Last 12 months
            - `d30` - Last 30 days
            - `h24` - Last 24 hours
            - `lasty` - Last Year
            - `lastm` - Last Month
            - `lastw` - Last Week
            - `yesterday` - Last Day

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            List of parameters

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

        Returns
        -------
        typing.List[StatisticsVendorQueryRecord]
            Success

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

        client = payabli(
            api_key="YOUR_API_KEY",
        )
        client.statistic.vendor_basic_stats(
            freq="m",
            id_vendor=1,
            mode="ytd",
        )
        """
        _response = self._raw_client.vendor_basic_stats(
            freq, id_vendor, mode, parameters=parameters, request_options=request_options
        )
        return _response.data


class AsyncStatisticClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawStatisticClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawStatisticClient
        """
        return self._raw_client

    async def basic_stats(
        self,
        entry_id: int,
        freq: str,
        level: int,
        mode: str,
        *,
        end_date: typing.Optional[str] = None,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        start_date: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[StatBasicQueryRecord]:
        """
        Retrieves the basic statistics for an organization or a paypoint, for a given time period, grouped by a particular frequency.

        Parameters
        ----------
        entry_id : int
            Identifier in Payabli for the entity.

        freq : str
            Frequency to group series. Allowed values:

            - `m` - monthly
            - `w` - weekly
            - `d` - daily
            - `h` - hourly

            For example, `w` groups the results by week.

        level : int
            The entry level for the request:
              - 0 for Organization
              - 2 for Paypoint

        mode : str
            Mode for the request. Allowed values:

            - `custom` - Allows you to set a custom date range
            - `ytd` - Year To Date
            - `mtd` - Month To Date
            - `wtd` - Week To Date
            - `today` - All current day
            - `m12` - Last 12 months
            - `d30` - Last 30 days
            - `h24` - Last 24 hours
            - `lasty` - Last Year
            - `lastm` - Last Month
            - `lastw` - Last Week
            - `yesterday` - Last Day


        end_date : typing.Optional[str]
            Used with `custom` mode. The end date for the range.
            Valid formats:
              - YYYY-mm-dd
              - YYYY/mm/dd
              - mm-dd-YYYY
              - mm/dd/YYYY

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            List of parameters.

        start_date : typing.Optional[str]
            Used with `custom` mode. The start date for the range.
            Valid formats:
               - YYYY-mm-dd
               - YYYY/mm/dd
               -  mm-dd-YYYY
               - mm/dd/YYYY

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

        Returns
        -------
        typing.List[StatBasicQueryRecord]
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.statistic.basic_stats(
                entry_id=1000000,
                freq="m",
                level=1,
                mode="ytd",
                end_date="2023-05-23",
                start_date="2023-03-23",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.basic_stats(
            entry_id,
            freq,
            level,
            mode,
            end_date=end_date,
            parameters=parameters,
            start_date=start_date,
            request_options=request_options,
        )
        return _response.data

    async def customer_basic_stats(
        self,
        customer_id: int,
        freq: str,
        mode: str,
        *,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[SubscriptionStatsQueryRecord]:
        """
        Retrieves the basic statistics for a customer for a specific time period, grouped by a selected frequency.

        Parameters
        ----------
        customer_id : int
            Payabli-generated customer ID. Maps to "Customer ID" column in PartnerHub.

        freq : str
            Frequency to group series. Allowed values:

            - `m` - monthly
            - `w` - weekly
            - `d` - daily
            - `h` - hourly

            For example, `w` groups the results by week.

        mode : str
            Mode for request. Allowed values:

            - `ytd` - Year To Date
            - `mtd` - Month To Date
            - `wtd` - Week To Date
            - `today` - All current day
            - `m12` - Last 12 months
            - `d30` - Last 30 days
            - `h24` - Last 24 hours
            - `lasty` - Last Year
            - `lastm` - Last Month
            - `lastw` - Last Week
            - `yesterday` - Last Day

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            List of parameters.

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

        Returns
        -------
        typing.List[SubscriptionStatsQueryRecord]
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.statistic.customer_basic_stats(
                customer_id=998,
                freq="m",
                mode="ytd",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.customer_basic_stats(
            customer_id, freq, mode, parameters=parameters, request_options=request_options
        )
        return _response.data

    async def sub_stats(
        self,
        entry_id: int,
        interval: str,
        level: int,
        *,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[StatBasicQueryRecord]:
        """
        Retrieves the subscription statistics for a given interval for a paypoint or organization.

        Parameters
        ----------
        entry_id : int
            Identifier in Payabli for the entity.

        interval : str
            Interval to get the data. Allowed values:

            - `all` - all intervals
            - `30` - 1-30 days
            - `60` - 31-60 days
            - `90` - 61-90 days
            - `plus` - +90 days

        level : int
            The entry level for the request:
              - 0 for Organization
              - 2 for Paypoint

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            List of parameters

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

        Returns
        -------
        typing.List[StatBasicQueryRecord]
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.statistic.sub_stats(
                entry_id=1000000,
                interval="30",
                level=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.sub_stats(
            entry_id, interval, level, parameters=parameters, request_options=request_options
        )
        return _response.data

    async def vendor_basic_stats(
        self,
        freq: str,
        id_vendor: int,
        mode: str,
        *,
        parameters: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[StatisticsVendorQueryRecord]:
        """
        Retrieve the basic statistics about a vendor for a given time period, grouped by frequency.

        Parameters
        ----------
        freq : str
            Frequency to group series. Allowed values:

            - `m` - monthly
            - `w` - weekly
            - `d` - daily
            - `h` - hourly

            For example, `w` groups the results by week.

        id_vendor : int
            Vendor ID.

        mode : str
            Mode for request. Allowed values:

            - `ytd` - Year To Date
            - `mtd` - Month To Date
            - `wtd` - Week To Date
            - `today` - All current day
            - `m12` - Last 12 months
            - `d30` - Last 30 days
            - `h24` - Last 24 hours
            - `lasty` - Last Year
            - `lastm` - Last Month
            - `lastw` - Last Week
            - `yesterday` - Last Day

        parameters : typing.Optional[typing.Dict[str, typing.Optional[str]]]
            List of parameters

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

        Returns
        -------
        typing.List[StatisticsVendorQueryRecord]
            Success

        Examples
        --------
        import asyncio

        from payabli import Asyncpayabli

        client = Asyncpayabli(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.statistic.vendor_basic_stats(
                freq="m",
                id_vendor=1,
                mode="ytd",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.vendor_basic_stats(
            freq, id_vendor, mode, parameters=parameters, request_options=request_options
        )
        return _response.data
