# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import Dict, Union
from datetime import datetime
from typing_extensions import Literal

import httpx

from ..._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
from ..._utils import maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
    to_raw_response_wrapper,
    to_streamed_response_wrapper,
    async_to_raw_response_wrapper,
    async_to_streamed_response_wrapper,
)
from ...pagination import SyncCursor, AsyncCursor
from ..._base_client import AsyncPaginator, make_request_options
from ...types.balances import (
    transaction_schedule_list_params,
    transaction_schedule_create_params,
    transaction_schedule_update_params,
    transaction_schedule_preview_params,
)
from ...types.balances.schedule_response import ScheduleResponse

__all__ = ["TransactionSchedulesResource", "AsyncTransactionSchedulesResource"]


class TransactionSchedulesResource(SyncAPIResource):
    @cached_property
    def with_raw_response(self) -> TransactionSchedulesResourceWithRawResponse:
        """
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/m3ter-com/m3ter-sdk-python#accessing-raw-response-data-eg-headers
        """
        return TransactionSchedulesResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> TransactionSchedulesResourceWithStreamingResponse:
        """
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/m3ter-com/m3ter-sdk-python#with_streaming_response
        """
        return TransactionSchedulesResourceWithStreamingResponse(self)

    def create(
        self,
        balance_id: str,
        *,
        org_id: str | None = None,
        amount: float,
        code: str,
        end_date: Union[str, datetime],
        frequency: Literal["DAILY", "WEEKLY", "MONTHLY", "ANNUALLY"],
        frequency_interval: int,
        name: str,
        start_date: Union[str, datetime],
        transaction_description: str,
        transaction_type_id: str,
        currency_paid: str | Omit = omit,
        custom_fields: Dict[str, Union[str, float]] | Omit = omit,
        paid: float | Omit = omit,
        version: int | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Create a new BalanceTransactionSchedule.

        Args:
          amount: The amount of each Balance Transaction created by this Schedule.

          code: The unique short code of the Balance Transaction Schedule.

          end_date: The end date (_in ISO-8601 format_) of the Balance Transaction Schedule.

              **NOTE:** End date is exclusive.

          frequency: Represents standard scheduling frequencies options for a job.

          frequency_interval: Used in conjunction with `frequency` to define how often Balance Transactions
              are generated by the Schedule. For example, if `frequency` is MONTHLY and
              `frequencyInterval` is 3, then Balance Transactions are generated every three
              months.

          name: The name of the Balance Transaction Schedule.

          start_date: The start date (_in ISO-8601 format_) of the Balance Transaction Schedule.

          transaction_description: The description of each Balance Transaction that will be created by this
              Schedule.

          transaction_type_id: The unique identifier (UUID) of the transaction type used to create Transactions
              by this Schedule. You can obtain a list of Transaction Types created for the
              Organization. See the the
              [List TransactionTypes](https://www.m3ter.com/docs/api#tag/TransactionType/operation/ListTransactionTypes)
              endpoint of this API Reference.

          currency_paid: The currency code of the payment if it differs from the Balance currency. For
              example: USD, GBP or EUR.

          custom_fields: User defined fields enabling you to attach custom data. The value for a custom
              field can be either a string or a number.

              If `customFields` can also be defined for this entity at the Organizational
              level, `customField` values defined at individual level override values of
              `customFields` with the same name defined at Organization level.

              See
              [Working with Custom Fields](https://www.m3ter.com/docs/guides/creating-and-managing-products/working-with-custom-fields)
              in the m3ter documentation for more information.

          paid: The payment amount if the payment currency differs from the Balance currency.

          version:
              The version number of the entity:

              - **Create entity:** Not valid for initial insertion of new entity - _do not use
                for Create_. On initial Create, version is set at 1 and listed in the
                response.
              - **Update Entity:** On Update, version is required and must match the existing
                version because a check is performed to ensure sequential versioning is
                preserved. Version is incremented by 1 and listed in the response.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        return self._post(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules",
            body=maybe_transform(
                {
                    "amount": amount,
                    "code": code,
                    "end_date": end_date,
                    "frequency": frequency,
                    "frequency_interval": frequency_interval,
                    "name": name,
                    "start_date": start_date,
                    "transaction_description": transaction_description,
                    "transaction_type_id": transaction_type_id,
                    "currency_paid": currency_paid,
                    "custom_fields": custom_fields,
                    "paid": paid,
                    "version": version,
                },
                transaction_schedule_create_params.TransactionScheduleCreateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ScheduleResponse,
        )

    def retrieve(
        self,
        id: str,
        *,
        org_id: str | None = None,
        balance_id: str,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Retrieve a BalanceTransactionSchedule for the given UUID.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        if not id:
            raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
        return self._get(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules/{id}",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ScheduleResponse,
        )

    def update(
        self,
        id: str,
        *,
        org_id: str | None = None,
        balance_id: str,
        amount: float,
        code: str,
        end_date: Union[str, datetime],
        frequency: Literal["DAILY", "WEEKLY", "MONTHLY", "ANNUALLY"],
        frequency_interval: int,
        name: str,
        start_date: Union[str, datetime],
        transaction_description: str,
        transaction_type_id: str,
        currency_paid: str | Omit = omit,
        custom_fields: Dict[str, Union[str, float]] | Omit = omit,
        paid: float | Omit = omit,
        version: int | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Update a BalanceTransactionSchedule for the given UUID.

        Args:
          amount: The amount of each Balance Transaction created by this Schedule.

          code: The unique short code of the Balance Transaction Schedule.

          end_date: The end date (_in ISO-8601 format_) of the Balance Transaction Schedule.

              **NOTE:** End date is exclusive.

          frequency: Represents standard scheduling frequencies options for a job.

          frequency_interval: Used in conjunction with `frequency` to define how often Balance Transactions
              are generated by the Schedule. For example, if `frequency` is MONTHLY and
              `frequencyInterval` is 3, then Balance Transactions are generated every three
              months.

          name: The name of the Balance Transaction Schedule.

          start_date: The start date (_in ISO-8601 format_) of the Balance Transaction Schedule.

          transaction_description: The description of each Balance Transaction that will be created by this
              Schedule.

          transaction_type_id: The unique identifier (UUID) of the transaction type used to create Transactions
              by this Schedule. You can obtain a list of Transaction Types created for the
              Organization. See the the
              [List TransactionTypes](https://www.m3ter.com/docs/api#tag/TransactionType/operation/ListTransactionTypes)
              endpoint of this API Reference.

          currency_paid: The currency code of the payment if it differs from the Balance currency. For
              example: USD, GBP or EUR.

          custom_fields: User defined fields enabling you to attach custom data. The value for a custom
              field can be either a string or a number.

              If `customFields` can also be defined for this entity at the Organizational
              level, `customField` values defined at individual level override values of
              `customFields` with the same name defined at Organization level.

              See
              [Working with Custom Fields](https://www.m3ter.com/docs/guides/creating-and-managing-products/working-with-custom-fields)
              in the m3ter documentation for more information.

          paid: The payment amount if the payment currency differs from the Balance currency.

          version:
              The version number of the entity:

              - **Create entity:** Not valid for initial insertion of new entity - _do not use
                for Create_. On initial Create, version is set at 1 and listed in the
                response.
              - **Update Entity:** On Update, version is required and must match the existing
                version because a check is performed to ensure sequential versioning is
                preserved. Version is incremented by 1 and listed in the response.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        if not id:
            raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
        return self._put(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules/{id}",
            body=maybe_transform(
                {
                    "amount": amount,
                    "code": code,
                    "end_date": end_date,
                    "frequency": frequency,
                    "frequency_interval": frequency_interval,
                    "name": name,
                    "start_date": start_date,
                    "transaction_description": transaction_description,
                    "transaction_type_id": transaction_type_id,
                    "currency_paid": currency_paid,
                    "custom_fields": custom_fields,
                    "paid": paid,
                    "version": version,
                },
                transaction_schedule_update_params.TransactionScheduleUpdateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ScheduleResponse,
        )

    def list(
        self,
        balance_id: str,
        *,
        org_id: str | None = None,
        ids: SequenceNotStr[str] | Omit = omit,
        next_token: str | Omit = omit,
        page_size: int | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> SyncCursor[ScheduleResponse]:
        """
        Retrieve a list of BalanceTransactionSchedule entities.

        Args:
          next_token: nextToken for multi page retrievals

          page_size: Number of BalanceTransactionSchedules to retrieve per page

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        return self._get_api_list(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules",
            page=SyncCursor[ScheduleResponse],
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "ids": ids,
                        "next_token": next_token,
                        "page_size": page_size,
                    },
                    transaction_schedule_list_params.TransactionScheduleListParams,
                ),
            ),
            model=ScheduleResponse,
        )

    def delete(
        self,
        id: str,
        *,
        org_id: str | None = None,
        balance_id: str,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Delete the BalanceTransactionSchedule for the given UUID.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        if not id:
            raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
        return self._delete(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules/{id}",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ScheduleResponse,
        )

    def preview(
        self,
        balance_id: str,
        *,
        org_id: str | None = None,
        amount: float,
        code: str,
        end_date: Union[str, datetime],
        frequency: Literal["DAILY", "WEEKLY", "MONTHLY", "ANNUALLY"],
        frequency_interval: int,
        name: str,
        start_date: Union[str, datetime],
        transaction_description: str,
        transaction_type_id: str,
        next_token: str | Omit = omit,
        page_size: int | Omit = omit,
        currency_paid: str | Omit = omit,
        custom_fields: Dict[str, Union[str, float]] | Omit = omit,
        paid: float | Omit = omit,
        version: int | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Previews the BalanceTransactions this Schedule would create, without persisting
        them. You can use this call to obtain a preview of the Transactions a Schedule
        you plan to create for a Balance would generate.

        Args:
          amount: The amount of each Balance Transaction created by this Schedule.

          code: The unique short code of the Balance Transaction Schedule.

          end_date: The end date (_in ISO-8601 format_) of the Balance Transaction Schedule.

              **NOTE:** End date is exclusive.

          frequency: Represents standard scheduling frequencies options for a job.

          frequency_interval: Used in conjunction with `frequency` to define how often Balance Transactions
              are generated by the Schedule. For example, if `frequency` is MONTHLY and
              `frequencyInterval` is 3, then Balance Transactions are generated every three
              months.

          name: The name of the Balance Transaction Schedule.

          start_date: The start date (_in ISO-8601 format_) of the Balance Transaction Schedule.

          transaction_description: The description of each Balance Transaction that will be created by this
              Schedule.

          transaction_type_id: The unique identifier (UUID) of the transaction type used to create Transactions
              by this Schedule. You can obtain a list of Transaction Types created for the
              Organization. See the the
              [List TransactionTypes](https://www.m3ter.com/docs/api#tag/TransactionType/operation/ListTransactionTypes)
              endpoint of this API Reference.

          next_token: nextToken for multi page retrievals

          page_size: Number of BalanceTransactions to retrieve per page

          currency_paid: The currency code of the payment if it differs from the Balance currency. For
              example: USD, GBP or EUR.

          custom_fields: User defined fields enabling you to attach custom data. The value for a custom
              field can be either a string or a number.

              If `customFields` can also be defined for this entity at the Organizational
              level, `customField` values defined at individual level override values of
              `customFields` with the same name defined at Organization level.

              See
              [Working with Custom Fields](https://www.m3ter.com/docs/guides/creating-and-managing-products/working-with-custom-fields)
              in the m3ter documentation for more information.

          paid: The payment amount if the payment currency differs from the Balance currency.

          version:
              The version number of the entity:

              - **Create entity:** Not valid for initial insertion of new entity - _do not use
                for Create_. On initial Create, version is set at 1 and listed in the
                response.
              - **Update Entity:** On Update, version is required and must match the existing
                version because a check is performed to ensure sequential versioning is
                preserved. Version is incremented by 1 and listed in the response.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        return self._post(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules/preview",
            body=maybe_transform(
                {
                    "amount": amount,
                    "code": code,
                    "end_date": end_date,
                    "frequency": frequency,
                    "frequency_interval": frequency_interval,
                    "name": name,
                    "start_date": start_date,
                    "transaction_description": transaction_description,
                    "transaction_type_id": transaction_type_id,
                    "currency_paid": currency_paid,
                    "custom_fields": custom_fields,
                    "paid": paid,
                    "version": version,
                },
                transaction_schedule_preview_params.TransactionSchedulePreviewParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "next_token": next_token,
                        "page_size": page_size,
                    },
                    transaction_schedule_preview_params.TransactionSchedulePreviewParams,
                ),
            ),
            cast_to=ScheduleResponse,
        )


class AsyncTransactionSchedulesResource(AsyncAPIResource):
    @cached_property
    def with_raw_response(self) -> AsyncTransactionSchedulesResourceWithRawResponse:
        """
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/m3ter-com/m3ter-sdk-python#accessing-raw-response-data-eg-headers
        """
        return AsyncTransactionSchedulesResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> AsyncTransactionSchedulesResourceWithStreamingResponse:
        """
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/m3ter-com/m3ter-sdk-python#with_streaming_response
        """
        return AsyncTransactionSchedulesResourceWithStreamingResponse(self)

    async def create(
        self,
        balance_id: str,
        *,
        org_id: str | None = None,
        amount: float,
        code: str,
        end_date: Union[str, datetime],
        frequency: Literal["DAILY", "WEEKLY", "MONTHLY", "ANNUALLY"],
        frequency_interval: int,
        name: str,
        start_date: Union[str, datetime],
        transaction_description: str,
        transaction_type_id: str,
        currency_paid: str | Omit = omit,
        custom_fields: Dict[str, Union[str, float]] | Omit = omit,
        paid: float | Omit = omit,
        version: int | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Create a new BalanceTransactionSchedule.

        Args:
          amount: The amount of each Balance Transaction created by this Schedule.

          code: The unique short code of the Balance Transaction Schedule.

          end_date: The end date (_in ISO-8601 format_) of the Balance Transaction Schedule.

              **NOTE:** End date is exclusive.

          frequency: Represents standard scheduling frequencies options for a job.

          frequency_interval: Used in conjunction with `frequency` to define how often Balance Transactions
              are generated by the Schedule. For example, if `frequency` is MONTHLY and
              `frequencyInterval` is 3, then Balance Transactions are generated every three
              months.

          name: The name of the Balance Transaction Schedule.

          start_date: The start date (_in ISO-8601 format_) of the Balance Transaction Schedule.

          transaction_description: The description of each Balance Transaction that will be created by this
              Schedule.

          transaction_type_id: The unique identifier (UUID) of the transaction type used to create Transactions
              by this Schedule. You can obtain a list of Transaction Types created for the
              Organization. See the the
              [List TransactionTypes](https://www.m3ter.com/docs/api#tag/TransactionType/operation/ListTransactionTypes)
              endpoint of this API Reference.

          currency_paid: The currency code of the payment if it differs from the Balance currency. For
              example: USD, GBP or EUR.

          custom_fields: User defined fields enabling you to attach custom data. The value for a custom
              field can be either a string or a number.

              If `customFields` can also be defined for this entity at the Organizational
              level, `customField` values defined at individual level override values of
              `customFields` with the same name defined at Organization level.

              See
              [Working with Custom Fields](https://www.m3ter.com/docs/guides/creating-and-managing-products/working-with-custom-fields)
              in the m3ter documentation for more information.

          paid: The payment amount if the payment currency differs from the Balance currency.

          version:
              The version number of the entity:

              - **Create entity:** Not valid for initial insertion of new entity - _do not use
                for Create_. On initial Create, version is set at 1 and listed in the
                response.
              - **Update Entity:** On Update, version is required and must match the existing
                version because a check is performed to ensure sequential versioning is
                preserved. Version is incremented by 1 and listed in the response.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        return await self._post(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules",
            body=await async_maybe_transform(
                {
                    "amount": amount,
                    "code": code,
                    "end_date": end_date,
                    "frequency": frequency,
                    "frequency_interval": frequency_interval,
                    "name": name,
                    "start_date": start_date,
                    "transaction_description": transaction_description,
                    "transaction_type_id": transaction_type_id,
                    "currency_paid": currency_paid,
                    "custom_fields": custom_fields,
                    "paid": paid,
                    "version": version,
                },
                transaction_schedule_create_params.TransactionScheduleCreateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ScheduleResponse,
        )

    async def retrieve(
        self,
        id: str,
        *,
        org_id: str | None = None,
        balance_id: str,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Retrieve a BalanceTransactionSchedule for the given UUID.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        if not id:
            raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
        return await self._get(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules/{id}",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ScheduleResponse,
        )

    async def update(
        self,
        id: str,
        *,
        org_id: str | None = None,
        balance_id: str,
        amount: float,
        code: str,
        end_date: Union[str, datetime],
        frequency: Literal["DAILY", "WEEKLY", "MONTHLY", "ANNUALLY"],
        frequency_interval: int,
        name: str,
        start_date: Union[str, datetime],
        transaction_description: str,
        transaction_type_id: str,
        currency_paid: str | Omit = omit,
        custom_fields: Dict[str, Union[str, float]] | Omit = omit,
        paid: float | Omit = omit,
        version: int | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Update a BalanceTransactionSchedule for the given UUID.

        Args:
          amount: The amount of each Balance Transaction created by this Schedule.

          code: The unique short code of the Balance Transaction Schedule.

          end_date: The end date (_in ISO-8601 format_) of the Balance Transaction Schedule.

              **NOTE:** End date is exclusive.

          frequency: Represents standard scheduling frequencies options for a job.

          frequency_interval: Used in conjunction with `frequency` to define how often Balance Transactions
              are generated by the Schedule. For example, if `frequency` is MONTHLY and
              `frequencyInterval` is 3, then Balance Transactions are generated every three
              months.

          name: The name of the Balance Transaction Schedule.

          start_date: The start date (_in ISO-8601 format_) of the Balance Transaction Schedule.

          transaction_description: The description of each Balance Transaction that will be created by this
              Schedule.

          transaction_type_id: The unique identifier (UUID) of the transaction type used to create Transactions
              by this Schedule. You can obtain a list of Transaction Types created for the
              Organization. See the the
              [List TransactionTypes](https://www.m3ter.com/docs/api#tag/TransactionType/operation/ListTransactionTypes)
              endpoint of this API Reference.

          currency_paid: The currency code of the payment if it differs from the Balance currency. For
              example: USD, GBP or EUR.

          custom_fields: User defined fields enabling you to attach custom data. The value for a custom
              field can be either a string or a number.

              If `customFields` can also be defined for this entity at the Organizational
              level, `customField` values defined at individual level override values of
              `customFields` with the same name defined at Organization level.

              See
              [Working with Custom Fields](https://www.m3ter.com/docs/guides/creating-and-managing-products/working-with-custom-fields)
              in the m3ter documentation for more information.

          paid: The payment amount if the payment currency differs from the Balance currency.

          version:
              The version number of the entity:

              - **Create entity:** Not valid for initial insertion of new entity - _do not use
                for Create_. On initial Create, version is set at 1 and listed in the
                response.
              - **Update Entity:** On Update, version is required and must match the existing
                version because a check is performed to ensure sequential versioning is
                preserved. Version is incremented by 1 and listed in the response.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        if not id:
            raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
        return await self._put(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules/{id}",
            body=await async_maybe_transform(
                {
                    "amount": amount,
                    "code": code,
                    "end_date": end_date,
                    "frequency": frequency,
                    "frequency_interval": frequency_interval,
                    "name": name,
                    "start_date": start_date,
                    "transaction_description": transaction_description,
                    "transaction_type_id": transaction_type_id,
                    "currency_paid": currency_paid,
                    "custom_fields": custom_fields,
                    "paid": paid,
                    "version": version,
                },
                transaction_schedule_update_params.TransactionScheduleUpdateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ScheduleResponse,
        )

    def list(
        self,
        balance_id: str,
        *,
        org_id: str | None = None,
        ids: SequenceNotStr[str] | Omit = omit,
        next_token: str | Omit = omit,
        page_size: int | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> AsyncPaginator[ScheduleResponse, AsyncCursor[ScheduleResponse]]:
        """
        Retrieve a list of BalanceTransactionSchedule entities.

        Args:
          next_token: nextToken for multi page retrievals

          page_size: Number of BalanceTransactionSchedules to retrieve per page

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        return self._get_api_list(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules",
            page=AsyncCursor[ScheduleResponse],
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "ids": ids,
                        "next_token": next_token,
                        "page_size": page_size,
                    },
                    transaction_schedule_list_params.TransactionScheduleListParams,
                ),
            ),
            model=ScheduleResponse,
        )

    async def delete(
        self,
        id: str,
        *,
        org_id: str | None = None,
        balance_id: str,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Delete the BalanceTransactionSchedule for the given UUID.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        if not id:
            raise ValueError(f"Expected a non-empty value for `id` but received {id!r}")
        return await self._delete(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules/{id}",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ScheduleResponse,
        )

    async def preview(
        self,
        balance_id: str,
        *,
        org_id: str | None = None,
        amount: float,
        code: str,
        end_date: Union[str, datetime],
        frequency: Literal["DAILY", "WEEKLY", "MONTHLY", "ANNUALLY"],
        frequency_interval: int,
        name: str,
        start_date: Union[str, datetime],
        transaction_description: str,
        transaction_type_id: str,
        next_token: str | Omit = omit,
        page_size: int | Omit = omit,
        currency_paid: str | Omit = omit,
        custom_fields: Dict[str, Union[str, float]] | Omit = omit,
        paid: float | Omit = omit,
        version: int | Omit = omit,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = not_given,
    ) -> ScheduleResponse:
        """
        Previews the BalanceTransactions this Schedule would create, without persisting
        them. You can use this call to obtain a preview of the Transactions a Schedule
        you plan to create for a Balance would generate.

        Args:
          amount: The amount of each Balance Transaction created by this Schedule.

          code: The unique short code of the Balance Transaction Schedule.

          end_date: The end date (_in ISO-8601 format_) of the Balance Transaction Schedule.

              **NOTE:** End date is exclusive.

          frequency: Represents standard scheduling frequencies options for a job.

          frequency_interval: Used in conjunction with `frequency` to define how often Balance Transactions
              are generated by the Schedule. For example, if `frequency` is MONTHLY and
              `frequencyInterval` is 3, then Balance Transactions are generated every three
              months.

          name: The name of the Balance Transaction Schedule.

          start_date: The start date (_in ISO-8601 format_) of the Balance Transaction Schedule.

          transaction_description: The description of each Balance Transaction that will be created by this
              Schedule.

          transaction_type_id: The unique identifier (UUID) of the transaction type used to create Transactions
              by this Schedule. You can obtain a list of Transaction Types created for the
              Organization. See the the
              [List TransactionTypes](https://www.m3ter.com/docs/api#tag/TransactionType/operation/ListTransactionTypes)
              endpoint of this API Reference.

          next_token: nextToken for multi page retrievals

          page_size: Number of BalanceTransactions to retrieve per page

          currency_paid: The currency code of the payment if it differs from the Balance currency. For
              example: USD, GBP or EUR.

          custom_fields: User defined fields enabling you to attach custom data. The value for a custom
              field can be either a string or a number.

              If `customFields` can also be defined for this entity at the Organizational
              level, `customField` values defined at individual level override values of
              `customFields` with the same name defined at Organization level.

              See
              [Working with Custom Fields](https://www.m3ter.com/docs/guides/creating-and-managing-products/working-with-custom-fields)
              in the m3ter documentation for more information.

          paid: The payment amount if the payment currency differs from the Balance currency.

          version:
              The version number of the entity:

              - **Create entity:** Not valid for initial insertion of new entity - _do not use
                for Create_. On initial Create, version is set at 1 and listed in the
                response.
              - **Update Entity:** On Update, version is required and must match the existing
                version because a check is performed to ensure sequential versioning is
                preserved. Version is incremented by 1 and listed in the response.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if org_id is None:
            org_id = self._client._get_org_id_path_param()
        if not org_id:
            raise ValueError(f"Expected a non-empty value for `org_id` but received {org_id!r}")
        if not balance_id:
            raise ValueError(f"Expected a non-empty value for `balance_id` but received {balance_id!r}")
        return await self._post(
            f"/organizations/{org_id}/balances/{balance_id}/balancetransactionschedules/preview",
            body=await async_maybe_transform(
                {
                    "amount": amount,
                    "code": code,
                    "end_date": end_date,
                    "frequency": frequency,
                    "frequency_interval": frequency_interval,
                    "name": name,
                    "start_date": start_date,
                    "transaction_description": transaction_description,
                    "transaction_type_id": transaction_type_id,
                    "currency_paid": currency_paid,
                    "custom_fields": custom_fields,
                    "paid": paid,
                    "version": version,
                },
                transaction_schedule_preview_params.TransactionSchedulePreviewParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {
                        "next_token": next_token,
                        "page_size": page_size,
                    },
                    transaction_schedule_preview_params.TransactionSchedulePreviewParams,
                ),
            ),
            cast_to=ScheduleResponse,
        )


class TransactionSchedulesResourceWithRawResponse:
    def __init__(self, transaction_schedules: TransactionSchedulesResource) -> None:
        self._transaction_schedules = transaction_schedules

        self.create = to_raw_response_wrapper(
            transaction_schedules.create,
        )
        self.retrieve = to_raw_response_wrapper(
            transaction_schedules.retrieve,
        )
        self.update = to_raw_response_wrapper(
            transaction_schedules.update,
        )
        self.list = to_raw_response_wrapper(
            transaction_schedules.list,
        )
        self.delete = to_raw_response_wrapper(
            transaction_schedules.delete,
        )
        self.preview = to_raw_response_wrapper(
            transaction_schedules.preview,
        )


class AsyncTransactionSchedulesResourceWithRawResponse:
    def __init__(self, transaction_schedules: AsyncTransactionSchedulesResource) -> None:
        self._transaction_schedules = transaction_schedules

        self.create = async_to_raw_response_wrapper(
            transaction_schedules.create,
        )
        self.retrieve = async_to_raw_response_wrapper(
            transaction_schedules.retrieve,
        )
        self.update = async_to_raw_response_wrapper(
            transaction_schedules.update,
        )
        self.list = async_to_raw_response_wrapper(
            transaction_schedules.list,
        )
        self.delete = async_to_raw_response_wrapper(
            transaction_schedules.delete,
        )
        self.preview = async_to_raw_response_wrapper(
            transaction_schedules.preview,
        )


class TransactionSchedulesResourceWithStreamingResponse:
    def __init__(self, transaction_schedules: TransactionSchedulesResource) -> None:
        self._transaction_schedules = transaction_schedules

        self.create = to_streamed_response_wrapper(
            transaction_schedules.create,
        )
        self.retrieve = to_streamed_response_wrapper(
            transaction_schedules.retrieve,
        )
        self.update = to_streamed_response_wrapper(
            transaction_schedules.update,
        )
        self.list = to_streamed_response_wrapper(
            transaction_schedules.list,
        )
        self.delete = to_streamed_response_wrapper(
            transaction_schedules.delete,
        )
        self.preview = to_streamed_response_wrapper(
            transaction_schedules.preview,
        )


class AsyncTransactionSchedulesResourceWithStreamingResponse:
    def __init__(self, transaction_schedules: AsyncTransactionSchedulesResource) -> None:
        self._transaction_schedules = transaction_schedules

        self.create = async_to_streamed_response_wrapper(
            transaction_schedules.create,
        )
        self.retrieve = async_to_streamed_response_wrapper(
            transaction_schedules.retrieve,
        )
        self.update = async_to_streamed_response_wrapper(
            transaction_schedules.update,
        )
        self.list = async_to_streamed_response_wrapper(
            transaction_schedules.list,
        )
        self.delete = async_to_streamed_response_wrapper(
            transaction_schedules.delete,
        )
        self.preview = async_to_streamed_response_wrapper(
            transaction_schedules.preview,
        )
