"""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 BankAccountsFilterAccountType(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 BankAccountsFilterStatus(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Filter by account status"""

    ACTIVE = "active"
    INACTIVE = "inactive"
    CLOSED = "closed"


class BankAccountsFilterTypedDict(TypedDict):
    name: NotRequired[str]
    r"""Filter by bank account name"""
    account_type: NotRequired[BankAccountsFilterAccountType]
    r"""Filter by account type"""
    status: NotRequired[BankAccountsFilterStatus]
    r"""Filter by account status"""


class BankAccountsFilter(BaseModel):
    name: Annotated[Optional[str], FieldMetadata(query=True)] = None
    r"""Filter by bank account name"""

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

    status: Annotated[
        Annotated[
            Optional[BankAccountsFilterStatus],
            PlainValidator(validate_open_enum(False)),
        ],
        FieldMetadata(query=True),
    ] = None
    r"""Filter by account status"""

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

    @field_serializer("status")
    def serialize_status(self, value):
        if isinstance(value, str):
            try:
                return models.BankAccountsFilterStatus(value)
            except ValueError:
                return value
        return value
