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

from __future__ import annotations

from typing import Optional

import httpx

from ..._types import Body, Omit, Query, Headers, NotGiven, 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 ...types.card import spending_constraint_update_full_params, spending_constraint_update_partial_params
from ..._base_client import make_request_options
from ...types.card.spending_constraint import SpendingConstraint

__all__ = ["SpendingConstraintResource", "AsyncSpendingConstraintResource"]


class SpendingConstraintResource(SyncAPIResource):
    @cached_property
    def with_raw_response(self) -> SpendingConstraintResourceWithRawResponse:
        """
        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/slashfi/slash-sdk-python#accessing-raw-response-data-eg-headers
        """
        return SpendingConstraintResourceWithRawResponse(self)

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

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

    def update_full(
        self,
        card_id: str,
        *,
        country_rule: Optional[spending_constraint_update_full_params.CountryRule] | Omit = omit,
        merchant_category_code_rule: Optional[spending_constraint_update_full_params.MerchantCategoryCodeRule]
        | Omit = omit,
        merchant_category_rule: Optional[spending_constraint_update_full_params.MerchantCategoryRule] | Omit = omit,
        merchant_rule: Optional[spending_constraint_update_full_params.MerchantRule] | Omit = omit,
        spending_rule: Optional[spending_constraint_update_full_params.SpendingRule] | 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,
    ) -> SpendingConstraint:
        """
        Fully replace a card's spending constraint.

        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 not card_id:
            raise ValueError(f"Expected a non-empty value for `card_id` but received {card_id!r}")
        return self._put(
            f"/card/{card_id}/spending-constraint",
            body=maybe_transform(
                {
                    "country_rule": country_rule,
                    "merchant_category_code_rule": merchant_category_code_rule,
                    "merchant_category_rule": merchant_category_rule,
                    "merchant_rule": merchant_rule,
                    "spending_rule": spending_rule,
                },
                spending_constraint_update_full_params.SpendingConstraintUpdateFullParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=SpendingConstraint,
        )

    def update_partial(
        self,
        card_id: str,
        *,
        country_rule: Optional[spending_constraint_update_partial_params.CountryRule] | Omit = omit,
        merchant_category_code_rule: Optional[spending_constraint_update_partial_params.MerchantCategoryCodeRule]
        | Omit = omit,
        merchant_category_rule: Optional[spending_constraint_update_partial_params.MerchantCategoryRule] | Omit = omit,
        merchant_rule: Optional[spending_constraint_update_partial_params.MerchantRule] | Omit = omit,
        spending_rule: Optional[spending_constraint_update_partial_params.SpendingRule] | 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,
    ) -> SpendingConstraint:
        """
        Apply a partial update to a card's spending constraint while preserving current
        properties applied. Properties set to "null" will be removed from the spending
        constraint.

        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 not card_id:
            raise ValueError(f"Expected a non-empty value for `card_id` but received {card_id!r}")
        return self._patch(
            f"/card/{card_id}/spending-constraint",
            body=maybe_transform(
                {
                    "country_rule": country_rule,
                    "merchant_category_code_rule": merchant_category_code_rule,
                    "merchant_category_rule": merchant_category_rule,
                    "merchant_rule": merchant_rule,
                    "spending_rule": spending_rule,
                },
                spending_constraint_update_partial_params.SpendingConstraintUpdatePartialParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=SpendingConstraint,
        )


class AsyncSpendingConstraintResource(AsyncAPIResource):
    @cached_property
    def with_raw_response(self) -> AsyncSpendingConstraintResourceWithRawResponse:
        """
        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/slashfi/slash-sdk-python#accessing-raw-response-data-eg-headers
        """
        return AsyncSpendingConstraintResourceWithRawResponse(self)

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

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

    async def update_full(
        self,
        card_id: str,
        *,
        country_rule: Optional[spending_constraint_update_full_params.CountryRule] | Omit = omit,
        merchant_category_code_rule: Optional[spending_constraint_update_full_params.MerchantCategoryCodeRule]
        | Omit = omit,
        merchant_category_rule: Optional[spending_constraint_update_full_params.MerchantCategoryRule] | Omit = omit,
        merchant_rule: Optional[spending_constraint_update_full_params.MerchantRule] | Omit = omit,
        spending_rule: Optional[spending_constraint_update_full_params.SpendingRule] | 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,
    ) -> SpendingConstraint:
        """
        Fully replace a card's spending constraint.

        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 not card_id:
            raise ValueError(f"Expected a non-empty value for `card_id` but received {card_id!r}")
        return await self._put(
            f"/card/{card_id}/spending-constraint",
            body=await async_maybe_transform(
                {
                    "country_rule": country_rule,
                    "merchant_category_code_rule": merchant_category_code_rule,
                    "merchant_category_rule": merchant_category_rule,
                    "merchant_rule": merchant_rule,
                    "spending_rule": spending_rule,
                },
                spending_constraint_update_full_params.SpendingConstraintUpdateFullParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=SpendingConstraint,
        )

    async def update_partial(
        self,
        card_id: str,
        *,
        country_rule: Optional[spending_constraint_update_partial_params.CountryRule] | Omit = omit,
        merchant_category_code_rule: Optional[spending_constraint_update_partial_params.MerchantCategoryCodeRule]
        | Omit = omit,
        merchant_category_rule: Optional[spending_constraint_update_partial_params.MerchantCategoryRule] | Omit = omit,
        merchant_rule: Optional[spending_constraint_update_partial_params.MerchantRule] | Omit = omit,
        spending_rule: Optional[spending_constraint_update_partial_params.SpendingRule] | 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,
    ) -> SpendingConstraint:
        """
        Apply a partial update to a card's spending constraint while preserving current
        properties applied. Properties set to "null" will be removed from the spending
        constraint.

        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 not card_id:
            raise ValueError(f"Expected a non-empty value for `card_id` but received {card_id!r}")
        return await self._patch(
            f"/card/{card_id}/spending-constraint",
            body=await async_maybe_transform(
                {
                    "country_rule": country_rule,
                    "merchant_category_code_rule": merchant_category_code_rule,
                    "merchant_category_rule": merchant_category_rule,
                    "merchant_rule": merchant_rule,
                    "spending_rule": spending_rule,
                },
                spending_constraint_update_partial_params.SpendingConstraintUpdatePartialParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=SpendingConstraint,
        )


class SpendingConstraintResourceWithRawResponse:
    def __init__(self, spending_constraint: SpendingConstraintResource) -> None:
        self._spending_constraint = spending_constraint

        self.update_full = to_raw_response_wrapper(
            spending_constraint.update_full,
        )
        self.update_partial = to_raw_response_wrapper(
            spending_constraint.update_partial,
        )


class AsyncSpendingConstraintResourceWithRawResponse:
    def __init__(self, spending_constraint: AsyncSpendingConstraintResource) -> None:
        self._spending_constraint = spending_constraint

        self.update_full = async_to_raw_response_wrapper(
            spending_constraint.update_full,
        )
        self.update_partial = async_to_raw_response_wrapper(
            spending_constraint.update_partial,
        )


class SpendingConstraintResourceWithStreamingResponse:
    def __init__(self, spending_constraint: SpendingConstraintResource) -> None:
        self._spending_constraint = spending_constraint

        self.update_full = to_streamed_response_wrapper(
            spending_constraint.update_full,
        )
        self.update_partial = to_streamed_response_wrapper(
            spending_constraint.update_partial,
        )


class AsyncSpendingConstraintResourceWithStreamingResponse:
    def __init__(self, spending_constraint: AsyncSpendingConstraintResource) -> None:
        self._spending_constraint = spending_constraint

        self.update_full = async_to_streamed_response_wrapper(
            spending_constraint.update_full,
        )
        self.update_partial = async_to_streamed_response_wrapper(
            spending_constraint.update_partial,
        )
