# 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.create_credit_grant_interface import CreateCreditGrantInterface
from ..types.create_fixed_rate_interface import CreateFixedRateInterface
from ..types.create_rate_card_response import CreateRateCardResponse
from ..types.create_rate_card_version_response import CreateRateCardVersionResponse
from ..types.credit_grant_resource import CreditGrantResource
from ..types.feature_access_resource import FeatureAccessResource
from ..types.fixed_rate_interface import FixedRateInterface
from ..types.get_rate_card_response import GetRateCardResponse
from ..types.list_rate_cards_response import ListRateCardsResponse
from .raw_client import AsyncRawRateCardsClient, RawRateCardsClient
from .types.create_rate_card_request_billing_interval import CreateRateCardRequestBillingInterval
from .types.create_rate_card_request_usage_based_rates_item import CreateRateCardRequestUsageBasedRatesItem
from .types.create_rate_card_version_request_usage_based_rates_item import (
    CreateRateCardVersionRequestUsageBasedRatesItem,
)
from .types.create_rate_card_version_request_version_type import CreateRateCardVersionRequestVersionType

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


class RateCardsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRateCardsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRateCardsClient
        """
        return self._raw_client

    def list_rate_cards(
        self,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListRateCardsResponse:
        """
        Parameters
        ----------
        limit : typing.Optional[int]

        offset : typing.Optional[int]

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

        Returns
        -------
        ListRateCardsResponse
            Successful Response

        Examples
        --------
        from lark import Lark

        client = Lark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )
        client.rate_cards.list_rate_cards(
            limit=1,
            offset=1,
        )
        """
        _response = self._raw_client.list_rate_cards(limit=limit, offset=offset, request_options=request_options)
        return _response.data

    def create_rate_card(
        self,
        *,
        name: str,
        description: str,
        usage_based_rates: typing.Sequence[CreateRateCardRequestUsageBasedRatesItem],
        billing_interval: CreateRateCardRequestBillingInterval,
        fixed_rates: typing.Optional[typing.Sequence[CreateFixedRateInterface]] = OMIT,
        credit_grants: typing.Optional[typing.Sequence[CreateCreditGrantInterface]] = OMIT,
        feature_access: typing.Optional[typing.Sequence[FeatureAccessResource]] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateRateCardResponse:
        """
        Parameters
        ----------
        name : str

        description : str

        usage_based_rates : typing.Sequence[CreateRateCardRequestUsageBasedRatesItem]

        billing_interval : CreateRateCardRequestBillingInterval

        fixed_rates : typing.Optional[typing.Sequence[CreateFixedRateInterface]]

        credit_grants : typing.Optional[typing.Sequence[CreateCreditGrantInterface]]

        feature_access : typing.Optional[typing.Sequence[FeatureAccessResource]]

        metadata : typing.Optional[typing.Dict[str, str]]

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

        Returns
        -------
        CreateRateCardResponse
            Successful Response

        Examples
        --------
        from lark import (
            Aggregation_Count,
            CreateDimensionCoordinateInterface,
            CreateDimensionInterface,
            CreatePricingMatrixCellInterface,
            CreatePricingMatrixInterface,
            CreatePricingMetricInterface,
            Lark,
        )
        from lark.rate_cards import CreateRateCardRequestUsageBasedRatesItem_Dimensional

        client = Lark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )
        client.rate_cards.create_rate_card(
            name="name",
            description="description",
            usage_based_rates=[
                CreateRateCardRequestUsageBasedRatesItem_Dimensional(
                    code="code",
                    name="name",
                    pricing_metric=CreatePricingMetricInterface(
                        name="name",
                        event_name="event_name",
                        aggregation=Aggregation_Count(),
                        unit="unit",
                    ),
                    dimensions=[
                        CreateDimensionInterface(
                            key="key",
                            values=["values"],
                        )
                    ],
                    pricing_matrix=CreatePricingMatrixInterface(
                        cells=[
                            CreatePricingMatrixCellInterface(
                                dimension_coordinates=[
                                    CreateDimensionCoordinateInterface(
                                        dimension_key="dimension_key",
                                        value="value",
                                    )
                                ],
                                price={
                                    "amount": {
                                        "value": 1,
                                        "currency_code": "currency_code",
                                    },
                                    "price_type": "flat",
                                },
                            )
                        ],
                    ),
                )
            ],
            billing_interval="monthly",
        )
        """
        _response = self._raw_client.create_rate_card(
            name=name,
            description=description,
            usage_based_rates=usage_based_rates,
            billing_interval=billing_interval,
            fixed_rates=fixed_rates,
            credit_grants=credit_grants,
            feature_access=feature_access,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    def get_rate_card(
        self, rate_card_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetRateCardResponse:
        """
        Parameters
        ----------
        rate_card_id : str

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

        Returns
        -------
        GetRateCardResponse
            Successful Response

        Examples
        --------
        from lark import Lark

        client = Lark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )
        client.rate_cards.get_rate_card(
            rate_card_id="rate_card_id",
        )
        """
        _response = self._raw_client.get_rate_card(rate_card_id, request_options=request_options)
        return _response.data

    def delete_rate_card(self, rate_card_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Parameters
        ----------
        rate_card_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from lark import Lark

        client = Lark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )
        client.rate_cards.delete_rate_card(
            rate_card_id="rate_card_id",
        )
        """
        _response = self._raw_client.delete_rate_card(rate_card_id, request_options=request_options)
        return _response.data

    def update_rate_card(self, rate_card_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> None:
        """
        Parameters
        ----------
        rate_card_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from lark import Lark

        client = Lark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )
        client.rate_cards.update_rate_card(
            rate_card_id="rate_card_id",
        )
        """
        _response = self._raw_client.update_rate_card(rate_card_id, request_options=request_options)
        return _response.data

    def create_rate_card_version(
        self,
        rate_card_id: str,
        *,
        name: str,
        description: str,
        usage_based_rates: typing.Sequence[CreateRateCardVersionRequestUsageBasedRatesItem],
        version_type: CreateRateCardVersionRequestVersionType,
        fixed_rates: typing.Optional[typing.Sequence[FixedRateInterface]] = OMIT,
        credit_grants: typing.Optional[typing.Sequence[CreditGrantResource]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateRateCardVersionResponse:
        """
        Parameters
        ----------
        rate_card_id : str

        name : str

        description : str

        usage_based_rates : typing.Sequence[CreateRateCardVersionRequestUsageBasedRatesItem]

        version_type : CreateRateCardVersionRequestVersionType

        fixed_rates : typing.Optional[typing.Sequence[FixedRateInterface]]

        credit_grants : typing.Optional[typing.Sequence[CreditGrantResource]]

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

        Returns
        -------
        CreateRateCardVersionResponse
            Successful Response

        Examples
        --------
        from lark import (
            Aggregation_Count,
            DimensionCoordinateInterface,
            DimensionInterface,
            Lark,
            PricingMatrixCellInterface,
            PricingMatrixInterface,
            PricingMetricInterface,
        )
        from lark.rate_cards import (
            CreateRateCardVersionRequestUsageBasedRatesItem_Dimensional,
        )

        client = Lark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )
        client.rate_cards.create_rate_card_version(
            rate_card_id="rate_card_id",
            name="name",
            description="description",
            usage_based_rates=[
                CreateRateCardVersionRequestUsageBasedRatesItem_Dimensional(
                    id="id",
                    code="code",
                    name="name",
                    description="description",
                    included_units=1,
                    pricing_metric=PricingMetricInterface(
                        id="id",
                        name="name",
                        event_name="event_name",
                        aggregation=Aggregation_Count(),
                        unit="unit",
                    ),
                    dimensions=[
                        DimensionInterface(
                            key="key",
                            values=["values"],
                        )
                    ],
                    pricing_matrix=PricingMatrixInterface(
                        cells=[
                            PricingMatrixCellInterface(
                                dimension_coordinates=[
                                    DimensionCoordinateInterface(
                                        dimension_key="dimension_key",
                                        value="value",
                                    )
                                ],
                                price={
                                    "amount": {
                                        "value": 1,
                                        "currency_code": "currency_code",
                                    },
                                    "price_type": "flat",
                                },
                            )
                        ],
                    ),
                )
            ],
            version_type="major",
        )
        """
        _response = self._raw_client.create_rate_card_version(
            rate_card_id,
            name=name,
            description=description,
            usage_based_rates=usage_based_rates,
            version_type=version_type,
            fixed_rates=fixed_rates,
            credit_grants=credit_grants,
            request_options=request_options,
        )
        return _response.data


class AsyncRateCardsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRateCardsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRateCardsClient
        """
        return self._raw_client

    async def list_rate_cards(
        self,
        *,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListRateCardsResponse:
        """
        Parameters
        ----------
        limit : typing.Optional[int]

        offset : typing.Optional[int]

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

        Returns
        -------
        ListRateCardsResponse
            Successful Response

        Examples
        --------
        import asyncio

        from lark import AsyncLark

        client = AsyncLark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.rate_cards.list_rate_cards(
                limit=1,
                offset=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_rate_cards(limit=limit, offset=offset, request_options=request_options)
        return _response.data

    async def create_rate_card(
        self,
        *,
        name: str,
        description: str,
        usage_based_rates: typing.Sequence[CreateRateCardRequestUsageBasedRatesItem],
        billing_interval: CreateRateCardRequestBillingInterval,
        fixed_rates: typing.Optional[typing.Sequence[CreateFixedRateInterface]] = OMIT,
        credit_grants: typing.Optional[typing.Sequence[CreateCreditGrantInterface]] = OMIT,
        feature_access: typing.Optional[typing.Sequence[FeatureAccessResource]] = OMIT,
        metadata: typing.Optional[typing.Dict[str, str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateRateCardResponse:
        """
        Parameters
        ----------
        name : str

        description : str

        usage_based_rates : typing.Sequence[CreateRateCardRequestUsageBasedRatesItem]

        billing_interval : CreateRateCardRequestBillingInterval

        fixed_rates : typing.Optional[typing.Sequence[CreateFixedRateInterface]]

        credit_grants : typing.Optional[typing.Sequence[CreateCreditGrantInterface]]

        feature_access : typing.Optional[typing.Sequence[FeatureAccessResource]]

        metadata : typing.Optional[typing.Dict[str, str]]

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

        Returns
        -------
        CreateRateCardResponse
            Successful Response

        Examples
        --------
        import asyncio

        from lark import (
            Aggregation_Count,
            AsyncLark,
            CreateDimensionCoordinateInterface,
            CreateDimensionInterface,
            CreatePricingMatrixCellInterface,
            CreatePricingMatrixInterface,
            CreatePricingMetricInterface,
        )
        from lark.rate_cards import CreateRateCardRequestUsageBasedRatesItem_Dimensional

        client = AsyncLark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.rate_cards.create_rate_card(
                name="name",
                description="description",
                usage_based_rates=[
                    CreateRateCardRequestUsageBasedRatesItem_Dimensional(
                        code="code",
                        name="name",
                        pricing_metric=CreatePricingMetricInterface(
                            name="name",
                            event_name="event_name",
                            aggregation=Aggregation_Count(),
                            unit="unit",
                        ),
                        dimensions=[
                            CreateDimensionInterface(
                                key="key",
                                values=["values"],
                            )
                        ],
                        pricing_matrix=CreatePricingMatrixInterface(
                            cells=[
                                CreatePricingMatrixCellInterface(
                                    dimension_coordinates=[
                                        CreateDimensionCoordinateInterface(
                                            dimension_key="dimension_key",
                                            value="value",
                                        )
                                    ],
                                    price={
                                        "amount": {
                                            "value": 1,
                                            "currency_code": "currency_code",
                                        },
                                        "price_type": "flat",
                                    },
                                )
                            ],
                        ),
                    )
                ],
                billing_interval="monthly",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_rate_card(
            name=name,
            description=description,
            usage_based_rates=usage_based_rates,
            billing_interval=billing_interval,
            fixed_rates=fixed_rates,
            credit_grants=credit_grants,
            feature_access=feature_access,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    async def get_rate_card(
        self, rate_card_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetRateCardResponse:
        """
        Parameters
        ----------
        rate_card_id : str

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

        Returns
        -------
        GetRateCardResponse
            Successful Response

        Examples
        --------
        import asyncio

        from lark import AsyncLark

        client = AsyncLark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.rate_cards.get_rate_card(
                rate_card_id="rate_card_id",
            )


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

    async def delete_rate_card(
        self, rate_card_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Parameters
        ----------
        rate_card_id : str

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from lark import AsyncLark

        client = AsyncLark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.rate_cards.delete_rate_card(
                rate_card_id="rate_card_id",
            )


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

    async def update_rate_card(
        self, rate_card_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Parameters
        ----------
        rate_card_id : str

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from lark import AsyncLark

        client = AsyncLark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.rate_cards.update_rate_card(
                rate_card_id="rate_card_id",
            )


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

    async def create_rate_card_version(
        self,
        rate_card_id: str,
        *,
        name: str,
        description: str,
        usage_based_rates: typing.Sequence[CreateRateCardVersionRequestUsageBasedRatesItem],
        version_type: CreateRateCardVersionRequestVersionType,
        fixed_rates: typing.Optional[typing.Sequence[FixedRateInterface]] = OMIT,
        credit_grants: typing.Optional[typing.Sequence[CreditGrantResource]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateRateCardVersionResponse:
        """
        Parameters
        ----------
        rate_card_id : str

        name : str

        description : str

        usage_based_rates : typing.Sequence[CreateRateCardVersionRequestUsageBasedRatesItem]

        version_type : CreateRateCardVersionRequestVersionType

        fixed_rates : typing.Optional[typing.Sequence[FixedRateInterface]]

        credit_grants : typing.Optional[typing.Sequence[CreditGrantResource]]

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

        Returns
        -------
        CreateRateCardVersionResponse
            Successful Response

        Examples
        --------
        import asyncio

        from lark import (
            Aggregation_Count,
            AsyncLark,
            DimensionCoordinateInterface,
            DimensionInterface,
            PricingMatrixCellInterface,
            PricingMatrixInterface,
            PricingMetricInterface,
        )
        from lark.rate_cards import (
            CreateRateCardVersionRequestUsageBasedRatesItem_Dimensional,
        )

        client = AsyncLark(
            api_key="YOUR_API_KEY",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.rate_cards.create_rate_card_version(
                rate_card_id="rate_card_id",
                name="name",
                description="description",
                usage_based_rates=[
                    CreateRateCardVersionRequestUsageBasedRatesItem_Dimensional(
                        id="id",
                        code="code",
                        name="name",
                        description="description",
                        included_units=1,
                        pricing_metric=PricingMetricInterface(
                            id="id",
                            name="name",
                            event_name="event_name",
                            aggregation=Aggregation_Count(),
                            unit="unit",
                        ),
                        dimensions=[
                            DimensionInterface(
                                key="key",
                                values=["values"],
                            )
                        ],
                        pricing_matrix=PricingMatrixInterface(
                            cells=[
                                PricingMatrixCellInterface(
                                    dimension_coordinates=[
                                        DimensionCoordinateInterface(
                                            dimension_key="dimension_key",
                                            value="value",
                                        )
                                    ],
                                    price={
                                        "amount": {
                                            "value": 1,
                                            "currency_code": "currency_code",
                                        },
                                        "price_type": "flat",
                                    },
                                )
                            ],
                        ),
                    )
                ],
                version_type="major",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_rate_card_version(
            rate_card_id,
            name=name,
            description=description,
            usage_based_rates=usage_based_rates,
            version_type=version_type,
            fixed_rates=fixed_rates,
            credit_grants=credit_grants,
            request_options=request_options,
        )
        return _response.data
