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

from __future__ import annotations
from .filtercondition import FilterCondition, FilterConditionTypedDict
from .sortcondition import SortCondition, SortConditionTypedDict
from .status import Status
from .usertype import UserType
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import NotRequired, TypedDict


UserFilterOrder = Literal[
    "asc",
    "desc",
]


class UserFilterTypedDict(TypedDict):
    end_time: NotRequired[str]
    expand: NotRequired[str]
    filters: NotRequired[List[FilterConditionTypedDict]]
    r"""filters allows complex filtering based on multiple fields"""
    limit: NotRequired[int]
    offset: NotRequired[int]
    order: NotRequired[UserFilterOrder]
    roles: NotRequired[List[str]]
    sort: NotRequired[List[SortConditionTypedDict]]
    start_time: NotRequired[str]
    status: NotRequired[Status]
    type: NotRequired[UserType]
    user_ids: NotRequired[List[str]]
    r"""Specific filters for users"""


class UserFilter(BaseModel):
    end_time: Optional[str] = None

    expand: Optional[str] = None

    filters: Optional[List[FilterCondition]] = None
    r"""filters allows complex filtering based on multiple fields"""

    limit: Optional[int] = None

    offset: Optional[int] = None

    order: Optional[UserFilterOrder] = None

    roles: Optional[List[str]] = None

    sort: Optional[List[SortCondition]] = None

    start_time: Optional[str] = None

    status: Optional[Status] = None

    type: Optional[UserType] = None

    user_ids: Optional[List[str]] = None
    r"""Specific filters for users"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "end_time",
                "expand",
                "filters",
                "limit",
                "offset",
                "order",
                "roles",
                "sort",
                "start_time",
                "status",
                "type",
                "user_ids",
            ]
        )
        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
