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

from __future__ import annotations
from .sortdirection import SortDirection
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 CustomersSortBy(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The field on which to sort the Customers"""

    CREATED_AT = "created_at"
    UPDATED_AT = "updated_at"


class CustomersSortTypedDict(TypedDict):
    by: NotRequired[CustomersSortBy]
    r"""The field on which to sort the Customers"""
    direction: NotRequired[SortDirection]
    r"""The direction in which to sort the results"""


class CustomersSort(BaseModel):
    by: Annotated[
        Annotated[Optional[CustomersSortBy], PlainValidator(validate_open_enum(False))],
        FieldMetadata(query=True),
    ] = None
    r"""The field on which to sort the Customers"""

    direction: Annotated[
        Annotated[Optional[SortDirection], PlainValidator(validate_open_enum(False))],
        FieldMetadata(query=True),
    ] = SortDirection.ASC
    r"""The direction in which to sort the results"""

    @field_serializer("by")
    def serialize_by(self, value):
        if isinstance(value, str):
            try:
                return models.CustomersSortBy(value)
            except ValueError:
                return value
        return value

    @field_serializer("direction")
    def serialize_direction(self, value):
        if isinstance(value, str):
            try:
                return models.SortDirection(value)
            except ValueError:
                return value
        return value
