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

from __future__ import annotations
from apideck_unify import models, utils
from apideck_unify.types import BaseModel
from apideck_unify.utils import FieldMetadata, validate_open_enum
from enum import Enum
from pydantic import field_serializer
from pydantic.functional_validators import PlainValidator
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class BankAccountFilterAccountType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Filter by account type"""

    CHECKING = "checking"
    SAVINGS = "savings"
    CREDIT_CARD = "credit_card"
    MONEY_MARKET = "money_market"
    LINE_OF_CREDIT = "line_of_credit"
    OTHER = "other"
    CASH = "cash"


class BankAccountFilterTypedDict(TypedDict):
    account_type: NotRequired[BankAccountFilterAccountType]
    r"""Filter by account type"""


class BankAccountFilter(BaseModel):
    account_type: Annotated[
        Annotated[
            Optional[BankAccountFilterAccountType],
            PlainValidator(validate_open_enum(False)),
        ],
        FieldMetadata(query=True),
    ] = None
    r"""Filter by account type"""

    @field_serializer("account_type")
    def serialize_account_type(self, value):
        if isinstance(value, str):
            try:
                return models.BankAccountFilterAccountType(value)
            except ValueError:
                return value
        return value
