"""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 CategoriesFilterType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The type of the category."""

    SUPPLIER = "supplier"
    EXPENSE = "expense"
    REVENUE = "revenue"
    CUSTOMER = "customer"


class CategoriesFilterTypedDict(TypedDict):
    type: NotRequired[CategoriesFilterType]
    r"""The type of the category."""


class CategoriesFilter(BaseModel):
    type: Annotated[
        Annotated[
            Optional[CategoriesFilterType], PlainValidator(validate_open_enum(False))
        ],
        FieldMetadata(query=True),
    ] = None
    r"""The type of the category."""

    @field_serializer("type")
    def serialize_type(self, value):
        if isinstance(value, str):
            try:
                return models.CategoriesFilterType(value)
            except ValueError:
                return value
        return value
