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

from __future__ import annotations
from .types_filtercondition import TypesFilterCondition, TypesFilterConditionTypedDict
from .types_sortcondition import TypesSortCondition, TypesSortConditionTypedDict
from .types_status import TypesStatus
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import NotRequired, TypedDict


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


class TypesGroupFilterTypedDict(TypedDict):
    end_time: NotRequired[str]
    entity_type: NotRequired[str]
    expand: NotRequired[str]
    filters: NotRequired[List[TypesFilterConditionTypedDict]]
    r"""filters allows complex filtering based on multiple fields"""
    group_ids: NotRequired[List[str]]
    r"""Group specific filters"""
    limit: NotRequired[int]
    lookup_key: NotRequired[str]
    name: NotRequired[str]
    offset: NotRequired[int]
    order: NotRequired[TypesGroupFilterOrder]
    sort: NotRequired[List[TypesSortConditionTypedDict]]
    start_time: NotRequired[str]
    status: NotRequired[TypesStatus]


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

    entity_type: Optional[str] = None

    expand: Optional[str] = None

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

    group_ids: Optional[List[str]] = None
    r"""Group specific filters"""

    limit: Optional[int] = None

    lookup_key: Optional[str] = None

    name: Optional[str] = None

    offset: Optional[int] = None

    order: Optional[TypesGroupFilterOrder] = None

    sort: Optional[List[TypesSortCondition]] = None

    start_time: Optional[str] = None

    status: Optional[TypesStatus] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "end_time",
                "entity_type",
                "expand",
                "filters",
                "group_ids",
                "limit",
                "lookup_key",
                "name",
                "offset",
                "order",
                "sort",
                "start_time",
                "status",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
