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

from __future__ import annotations
from .createauthorizeduserupdate import (
    CreateAuthorizedUserUpdate,
    CreateAuthorizedUserUpdateTypedDict,
)
from .updateissuedcardstate import UpdateIssuedCardState
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 UpdateIssuedCardTypedDict(TypedDict):
    state: NotRequired[UpdateIssuedCardState]
    r"""Updates the state of a Moov issued card.
    - `closed`: The card is permanently deactivated and cannot approve authorizations. A card can be closed by request or when it expires.
    """
    memo: NotRequired[str]
    authorized_user: NotRequired[CreateAuthorizedUserUpdateTypedDict]
    r"""Fields for identifying an authorized individual."""


class UpdateIssuedCard(BaseModel):
    state: Optional[UpdateIssuedCardState] = None
    r"""Updates the state of a Moov issued card.
    - `closed`: The card is permanently deactivated and cannot approve authorizations. A card can be closed by request or when it expires.
    """

    memo: Optional[str] = None

    authorized_user: Annotated[
        Optional[CreateAuthorizedUserUpdate], pydantic.Field(alias="authorizedUser")
    ] = None
    r"""Fields for identifying an authorized individual."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["state", "memo", "authorizedUser"])
        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:
    UpdateIssuedCard.model_rebuild()
except NameError:
    pass
