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

from __future__ import annotations
from .instantbankfailurecode import InstantBankFailureCode
from .instantbanknetwork import InstantBankNetwork
from .instantbanktransactionstatus import InstantBankTransactionStatus
from datetime import datetime
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 InstantBankTransactionDetailsTypedDict(TypedDict):
    r"""Instant-bank specific details about the transaction."""

    network: InstantBankNetwork
    r"""The network that the transaction was processed on."""
    status: InstantBankTransactionStatus
    r"""Status of a transaction within the instant-bank lifecycle."""
    network_response_code: NotRequired[str]
    r"""Response code returned by network on failure."""
    failure_code: NotRequired[InstantBankFailureCode]
    r"""Status codes for instant-bank failures."""
    end_to_end_id: NotRequired[str]
    initiated_on: NotRequired[datetime]
    completed_on: NotRequired[datetime]
    failed_on: NotRequired[datetime]
    accepted_without_posting_on: NotRequired[datetime]


class InstantBankTransactionDetails(BaseModel):
    r"""Instant-bank specific details about the transaction."""

    network: InstantBankNetwork
    r"""The network that the transaction was processed on."""

    status: InstantBankTransactionStatus
    r"""Status of a transaction within the instant-bank lifecycle."""

    network_response_code: Annotated[
        Optional[str], pydantic.Field(alias="networkResponseCode")
    ] = None
    r"""Response code returned by network on failure."""

    failure_code: Annotated[
        Optional[InstantBankFailureCode], pydantic.Field(alias="failureCode")
    ] = None
    r"""Status codes for instant-bank failures."""

    end_to_end_id: Annotated[Optional[str], pydantic.Field(alias="endToEndID")] = None

    initiated_on: Annotated[Optional[datetime], pydantic.Field(alias="initiatedOn")] = (
        None
    )

    completed_on: Annotated[Optional[datetime], pydantic.Field(alias="completedOn")] = (
        None
    )

    failed_on: Annotated[Optional[datetime], pydantic.Field(alias="failedOn")] = None

    accepted_without_posting_on: Annotated[
        Optional[datetime], pydantic.Field(alias="acceptedWithoutPostingOn")
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "networkResponseCode",
                "failureCode",
                "endToEndID",
                "initiatedOn",
                "completedOn",
                "failedOn",
                "acceptedWithoutPostingOn",
            ]
        )
        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:
    InstantBankTransactionDetails.model_rebuild()
except NameError:
    pass
