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

from __future__ import annotations
from codat_bankfeeds.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class BankFeedAccountMappingResponseTypedDict(TypedDict):
    error: NotRequired[Nullable[str]]
    r"""Error returned during the post request"""
    source_account_id: NotRequired[str]
    r"""Unique ID for the source account."""
    status: NotRequired[Nullable[str]]
    r"""Status of the POST request."""
    target_account_id: NotRequired[Nullable[str]]
    r"""Unique ID for the target account."""


class BankFeedAccountMappingResponse(BaseModel):
    error: OptionalNullable[str] = UNSET
    r"""Error returned during the post request"""

    source_account_id: Annotated[
        Optional[str], pydantic.Field(alias="sourceAccountId")
    ] = None
    r"""Unique ID for the source account."""

    status: OptionalNullable[str] = UNSET
    r"""Status of the POST request."""

    target_account_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="targetAccountId")
    ] = UNSET
    r"""Unique ID for the target account."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["error", "sourceAccountId", "status", "targetAccountId"]
        nullable_fields = ["error", "status", "targetAccountId"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
