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

from __future__ import annotations
from .achreturncode import ACHReturnCode
from .rtprejectioncode import RTPRejectionCode
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


class BankAccountExceptionTypedDict(TypedDict):
    r"""Reason for, and details related to, an `errored` or `verificationFailed` bank account status."""

    description: str
    r"""Details related to an `errored` or `verificationFailed` bank account status."""
    ach_return_code: NotRequired[ACHReturnCode]
    r"""The return code of an ACH transaction that caused the bank account status to change.

    - R02: Account Closed
    - R03: No Account/Unable to Locate Account
    - R04: Invalid Account Number
    - R05: Improper Debit to Consumer Account
    - R07: Authorization Revoked by Customer
    - R08: Payment Stopped
    - R10: Customer Advises Originator is Not Known or Authorized to Receiver
    - R11: Customer Advises Entry Not in Accordance with the Terms of the Authorization
    - R12: Branch Sold to Another DFI
    - R13: RDFI not qualified to participate
    - R14: Representative payee deceased or unable to continue in that capacity
    - R15: Beneficiary or bank account holder
    - R16: Bank account frozen
    - R17: Entry with Invalid Account Number Initiated Under Questionable Circumstances
    - R20: Non-payment bank account
    - R23: Credit entry refused by receiver
    - R29: Corporate customer advises not authorized
    - R34: Limited participation RDFI
    - R38: Stop Payment on Source Document (Adjustment Entry)
    - R39: Improper Source Document
    """
    rtp_rejection_code: NotRequired[RTPRejectionCode]
    r"""The rejection code of an RTP transaction that caused the bank account status to change.

    - AC03: Account Invalid
    - AC04: Account Closed
    - AC06: Account Blocked
    - AC14: Creditor Account Type Invalid
    - AG01: Transactions Forbidden On Account
    - AG03: Transaction Type Not Supported
    - MD07: Customer Deceased
    """
    fednow_rejection_code: NotRequired[str]
    r"""The rejection code of a FedNow transaction that caused the bank account status to change.

    - AC02: Debtor account is invalid
    - AC03: Creditor account is invalid
    - AC04: Account closed
    - AC06: Account is blocked
    - AC07: Creditor account closed
    - AC10: Debtor account currency is invalid or missing
    - AC11: Creditor account currency is invalid or missing
    - AC13: Debtor account type missing or invalid
    - AC14: Creditor account type missing or invalid
    - AG01: Transaction is forbidden on this type of account
    - AG03: Transaction type is not supported/authorized on this account
    - BE06: End customer specified is not known at associated Sort/National Bank Code or no longer exists in the books
    - DUPL: Payment is a duplicate of another payment
    - MD07: End customer is deceased
    - NOAT: Receiving customer account does not support/accept this message type
    - RC02: Bank identifier is invalid or missing
    - RC03: Debtor FI identifier is invalid or missing
    - RC04: Creditor FI identifier is invalid or missing
    """


class BankAccountException(BaseModel):
    r"""Reason for, and details related to, an `errored` or `verificationFailed` bank account status."""

    description: str
    r"""Details related to an `errored` or `verificationFailed` bank account status."""

    ach_return_code: Annotated[
        Optional[ACHReturnCode], pydantic.Field(alias="achReturnCode")
    ] = None
    r"""The return code of an ACH transaction that caused the bank account status to change.

    - R02: Account Closed
    - R03: No Account/Unable to Locate Account
    - R04: Invalid Account Number
    - R05: Improper Debit to Consumer Account
    - R07: Authorization Revoked by Customer
    - R08: Payment Stopped
    - R10: Customer Advises Originator is Not Known or Authorized to Receiver
    - R11: Customer Advises Entry Not in Accordance with the Terms of the Authorization
    - R12: Branch Sold to Another DFI
    - R13: RDFI not qualified to participate
    - R14: Representative payee deceased or unable to continue in that capacity
    - R15: Beneficiary or bank account holder
    - R16: Bank account frozen
    - R17: Entry with Invalid Account Number Initiated Under Questionable Circumstances
    - R20: Non-payment bank account
    - R23: Credit entry refused by receiver
    - R29: Corporate customer advises not authorized
    - R34: Limited participation RDFI
    - R38: Stop Payment on Source Document (Adjustment Entry)
    - R39: Improper Source Document
    """

    rtp_rejection_code: Annotated[
        Optional[RTPRejectionCode], pydantic.Field(alias="rtpRejectionCode")
    ] = None
    r"""The rejection code of an RTP transaction that caused the bank account status to change.

    - AC03: Account Invalid
    - AC04: Account Closed
    - AC06: Account Blocked
    - AC14: Creditor Account Type Invalid
    - AG01: Transactions Forbidden On Account
    - AG03: Transaction Type Not Supported
    - MD07: Customer Deceased
    """

    fednow_rejection_code: Annotated[
        Optional[str], pydantic.Field(alias="fednowRejectionCode")
    ] = None
    r"""The rejection code of a FedNow transaction that caused the bank account status to change.

    - AC02: Debtor account is invalid
    - AC03: Creditor account is invalid
    - AC04: Account closed
    - AC06: Account is blocked
    - AC07: Creditor account closed
    - AC10: Debtor account currency is invalid or missing
    - AC11: Creditor account currency is invalid or missing
    - AC13: Debtor account type missing or invalid
    - AC14: Creditor account type missing or invalid
    - AG01: Transaction is forbidden on this type of account
    - AG03: Transaction type is not supported/authorized on this account
    - BE06: End customer specified is not known at associated Sort/National Bank Code or no longer exists in the books
    - DUPL: Payment is a duplicate of another payment
    - MD07: End customer is deceased
    - NOAT: Receiving customer account does not support/accept this message type
    - RC02: Bank identifier is invalid or missing
    - RC03: Debtor FI identifier is invalid or missing
    - RC04: Creditor FI identifier is invalid or missing
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["achReturnCode", "rtpRejectionCode", "fednowRejectionCode"]
        )
        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:
    BankAccountException.model_rebuild()
except NameError:
    pass
