"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .amountdecimal import AmountDecimal, AmountDecimalTypedDict
from .billingsummarydetails import BillingSummaryDetails, BillingSummaryDetailsTypedDict
from .billingsummaryinterchange import (
    BillingSummaryInterchange,
    BillingSummaryInterchangeTypedDict,
)
from .partnerfees import PartnerFees, PartnerFeesTypedDict
from moovio_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict, deprecated


@deprecated(
    "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
)
class BillingSummaryVolumeAmountTypedDict(TypedDict):
    r"""The total transaction volume amount. This field is deprecated and will be removed in a future release."""

    currency: str
    r"""A 3-letter ISO 4217 currency code."""
    value_decimal: str
    r"""A decimal-formatted numerical string that represents up to 9 decimal place precision.

    For example, $12.987654321 is '12.987654321'.
    """


@deprecated(
    "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
)
class BillingSummaryVolumeAmount(BaseModel):
    r"""The total transaction volume amount. This field is deprecated and will be removed in a future release."""

    currency: str
    r"""A 3-letter ISO 4217 currency code."""

    value_decimal: Annotated[str, pydantic.Field(alias="valueDecimal")]
    r"""A decimal-formatted numerical string that represents up to 9 decimal place precision.

    For example, $12.987654321 is '12.987654321'.
    """


class CardAcquiringTypedDict(TypedDict):
    r"""A summary of card acquiring fees."""

    volume_amount: NotRequired[BillingSummaryVolumeAmountTypedDict]
    r"""The total transaction volume amount. This field is deprecated and will be removed in a future release."""
    volume_count: NotRequired[int]
    r"""The total number of transactions. This field is deprecated and will be removed in a future release."""
    fee_amount: NotRequired[AmountDecimalTypedDict]
    r"""The total fee amount."""
    merchant_fees_collected: NotRequired[AmountDecimalTypedDict]
    r"""Total fee revenue collected from merchants."""
    partner_fees_assessed: NotRequired[AmountDecimalTypedDict]
    r"""Total fee costs incurred by the partner."""
    net_income: NotRequired[AmountDecimalTypedDict]
    r"""Net revenue after deducting partner fee costs."""
    interchange_fees: NotRequired[BillingSummaryInterchangeTypedDict]
    r"""A summary of interchange fees by card brand."""


class CardAcquiring(BaseModel):
    r"""A summary of card acquiring fees."""

    volume_amount: Annotated[
        Optional[BillingSummaryVolumeAmount],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.",
            alias="volumeAmount",
        ),
    ] = None
    r"""The total transaction volume amount. This field is deprecated and will be removed in a future release."""

    volume_count: Annotated[
        Optional[int],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.",
            alias="volumeCount",
        ),
    ] = None
    r"""The total number of transactions. This field is deprecated and will be removed in a future release."""

    fee_amount: Annotated[
        Optional[AmountDecimal], pydantic.Field(alias="feeAmount")
    ] = None
    r"""The total fee amount."""

    merchant_fees_collected: Annotated[
        Optional[AmountDecimal], pydantic.Field(alias="merchantFeesCollected")
    ] = None
    r"""Total fee revenue collected from merchants."""

    partner_fees_assessed: Annotated[
        Optional[AmountDecimal], pydantic.Field(alias="partnerFeesAssessed")
    ] = None
    r"""Total fee costs incurred by the partner."""

    net_income: Annotated[
        Optional[AmountDecimal], pydantic.Field(alias="netIncome")
    ] = None
    r"""Net revenue after deducting partner fee costs."""

    interchange_fees: Annotated[
        Optional[BillingSummaryInterchange], pydantic.Field(alias="interchangeFees")
    ] = None
    r"""A summary of interchange fees by card brand."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "volumeAmount",
                "volumeCount",
                "feeAmount",
                "merchantFeesCollected",
                "partnerFeesAssessed",
                "netIncome",
                "interchangeFees",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


@deprecated(
    "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
)
class BillingSummaryPlatformFeesTypedDict(TypedDict):
    r"""The total amount of platform fees. This field is deprecated and will be removed in a future release. Use summary.accountFees."""

    currency: str
    r"""A 3-letter ISO 4217 currency code."""
    value_decimal: str
    r"""A decimal-formatted numerical string that represents up to 9 decimal place precision.

    For example, $12.987654321 is '12.987654321'.
    """


@deprecated(
    "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
)
class BillingSummaryPlatformFees(BaseModel):
    r"""The total amount of platform fees. This field is deprecated and will be removed in a future release. Use summary.accountFees."""

    currency: str
    r"""A 3-letter ISO 4217 currency code."""

    value_decimal: Annotated[str, pydantic.Field(alias="valueDecimal")]
    r"""A decimal-formatted numerical string that represents up to 9 decimal place precision.

    For example, $12.987654321 is '12.987654321'.
    """


@deprecated(
    "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
)
class AdjustmentFeesTypedDict(TypedDict):
    r"""The total amount of adjustment fees. This field is deprecated and will be removed in a future release."""

    currency: str
    r"""A 3-letter ISO 4217 currency code."""
    value_decimal: str
    r"""A decimal-formatted numerical string that represents up to 9 decimal place precision.

    For example, $12.987654321 is '12.987654321'.
    """


@deprecated(
    "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
)
class AdjustmentFees(BaseModel):
    r"""The total amount of adjustment fees. This field is deprecated and will be removed in a future release."""

    currency: str
    r"""A 3-letter ISO 4217 currency code."""

    value_decimal: Annotated[str, pydantic.Field(alias="valueDecimal")]
    r"""A decimal-formatted numerical string that represents up to 9 decimal place precision.

    For example, $12.987654321 is '12.987654321'.
    """


@deprecated(
    "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
)
class OtherFeesTypedDict(TypedDict):
    r"""The total amount of other card fees. This field is deprecated and will be removed in a future release. Use summary.otherCardFees."""

    currency: str
    r"""A 3-letter ISO 4217 currency code."""
    value_decimal: str
    r"""A decimal-formatted numerical string that represents up to 9 decimal place precision.

    For example, $12.987654321 is '12.987654321'.
    """


@deprecated(
    "warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
)
class OtherFees(BaseModel):
    r"""The total amount of other card fees. This field is deprecated and will be removed in a future release. Use summary.otherCardFees."""

    currency: str
    r"""A 3-letter ISO 4217 currency code."""

    value_decimal: Annotated[str, pydantic.Field(alias="valueDecimal")]
    r"""A decimal-formatted numerical string that represents up to 9 decimal place precision.

    For example, $12.987654321 is '12.987654321'.
    """


class BillingSummaryTypedDict(TypedDict):
    r"""A summary of all fees included in a statement."""

    card_acquiring: NotRequired[CardAcquiringTypedDict]
    r"""A summary of card acquiring fees."""
    ach: NotRequired[BillingSummaryDetailsTypedDict]
    r"""A summary of ACH fees."""
    instant_payments: NotRequired[BillingSummaryDetailsTypedDict]
    r"""A summary of instant payment fees."""
    platform_fees: NotRequired[BillingSummaryPlatformFeesTypedDict]
    r"""The total amount of platform fees. This field is deprecated and will be removed in a future release. Use summary.accountFees."""
    account_fees: NotRequired[BillingSummaryDetailsTypedDict]
    r"""A summary of account fees."""
    adjustment_fees: NotRequired[AdjustmentFeesTypedDict]
    r"""The total amount of adjustment fees. This field is deprecated and will be removed in a future release."""
    other_fees: NotRequired[OtherFeesTypedDict]
    r"""The total amount of other card fees. This field is deprecated and will be removed in a future release. Use summary.otherCardFees."""
    other_card_fees: NotRequired[BillingSummaryDetailsTypedDict]
    r"""A summary of other card fees."""
    total: NotRequired[AmountDecimalTypedDict]
    r"""The total amount of all fees."""
    net_income_subtotal: NotRequired[BillingSummaryDetailsTypedDict]
    r"""Total net revenue after deducting total partner fees."""
    revenue_share: NotRequired[str]
    r"""Partner’s share of the net income, expressed as a percentage."""
    residual_subtotal: NotRequired[AmountDecimalTypedDict]
    r"""The portion of net income allocated to the partner before monthly partner costs."""
    monthly_partner_costs: NotRequired[PartnerFeesTypedDict]
    r"""Monthly partner costs that are charged separately and not included in residual subtotal (e.g. platform fees, minimums)."""
    net_partner_payment: NotRequired[AmountDecimalTypedDict]
    r"""Final partner payment after deducting monthlyPartnerCosts."""


class BillingSummary(BaseModel):
    r"""A summary of all fees included in a statement."""

    card_acquiring: Annotated[
        Optional[CardAcquiring], pydantic.Field(alias="cardAcquiring")
    ] = None
    r"""A summary of card acquiring fees."""

    ach: Optional[BillingSummaryDetails] = None
    r"""A summary of ACH fees."""

    instant_payments: Annotated[
        Optional[BillingSummaryDetails], pydantic.Field(alias="instantPayments")
    ] = None
    r"""A summary of instant payment fees."""

    platform_fees: Annotated[
        Optional[BillingSummaryPlatformFees],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.",
            alias="platformFees",
        ),
    ] = None
    r"""The total amount of platform fees. This field is deprecated and will be removed in a future release. Use summary.accountFees."""

    account_fees: Annotated[
        Optional[BillingSummaryDetails], pydantic.Field(alias="accountFees")
    ] = None
    r"""A summary of account fees."""

    adjustment_fees: Annotated[
        Optional[AdjustmentFees],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.",
            alias="adjustmentFees",
        ),
    ] = None
    r"""The total amount of adjustment fees. This field is deprecated and will be removed in a future release."""

    other_fees: Annotated[
        Optional[OtherFees],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible.",
            alias="otherFees",
        ),
    ] = None
    r"""The total amount of other card fees. This field is deprecated and will be removed in a future release. Use summary.otherCardFees."""

    other_card_fees: Annotated[
        Optional[BillingSummaryDetails], pydantic.Field(alias="otherCardFees")
    ] = None
    r"""A summary of other card fees."""

    total: Optional[AmountDecimal] = None
    r"""The total amount of all fees."""

    net_income_subtotal: Annotated[
        Optional[BillingSummaryDetails], pydantic.Field(alias="netIncomeSubtotal")
    ] = None
    r"""Total net revenue after deducting total partner fees."""

    revenue_share: Annotated[Optional[str], pydantic.Field(alias="revenueShare")] = None
    r"""Partner’s share of the net income, expressed as a percentage."""

    residual_subtotal: Annotated[
        Optional[AmountDecimal], pydantic.Field(alias="residualSubtotal")
    ] = None
    r"""The portion of net income allocated to the partner before monthly partner costs."""

    monthly_partner_costs: Annotated[
        Optional[PartnerFees], pydantic.Field(alias="monthlyPartnerCosts")
    ] = None
    r"""Monthly partner costs that are charged separately and not included in residual subtotal (e.g. platform fees, minimums)."""

    net_partner_payment: Annotated[
        Optional[AmountDecimal], pydantic.Field(alias="netPartnerPayment")
    ] = None
    r"""Final partner payment after deducting monthlyPartnerCosts."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "cardAcquiring",
                "ach",
                "instantPayments",
                "platformFees",
                "accountFees",
                "adjustmentFees",
                "otherFees",
                "otherCardFees",
                "total",
                "netIncomeSubtotal",
                "revenueShare",
                "residualSubtotal",
                "monthlyPartnerCosts",
                "netPartnerPayment",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    BillingSummaryVolumeAmount.model_rebuild()
except NameError:
    pass
try:
    CardAcquiring.model_rebuild()
except NameError:
    pass
try:
    BillingSummaryPlatformFees.model_rebuild()
except NameError:
    pass
try:
    AdjustmentFees.model_rebuild()
except NameError:
    pass
try:
    OtherFees.model_rebuild()
except NameError:
    pass
try:
    BillingSummary.model_rebuild()
except NameError:
    pass
