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

from __future__ import annotations
from .filtercondition import FilterCondition, FilterConditionTypedDict
from .queryfilter import QueryFilter, QueryFilterTypedDict
from .sortcondition import SortCondition, SortConditionTypedDict
from .status import Status
from .timerangefilter import TimeRangeFilter, TimeRangeFilterTypedDict
from flexprice_py.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class CostsheetFilterTypedDict(TypedDict):
    costsheet_i_ds: NotRequired[List[str]]
    r"""CostsheetIDs allows filtering by specific costsheet IDs"""
    environment_id: NotRequired[str]
    r"""EnvironmentID filters by specific environment ID"""
    filters: NotRequired[List[FilterConditionTypedDict]]
    r"""Filters contains custom filtering conditions"""
    lookup_key: NotRequired[str]
    r"""LookupKey filters by lookup key"""
    name: NotRequired[str]
    r"""Name filters by costsheet name"""
    query_filter: NotRequired[QueryFilterTypedDict]
    sort: NotRequired[List[SortConditionTypedDict]]
    r"""Sort specifies result ordering preferences"""
    status: NotRequired[Status]
    tenant_id: NotRequired[str]
    r"""TenantID filters by specific tenant ID"""
    time_range_filter: NotRequired[TimeRangeFilterTypedDict]


class CostsheetFilter(BaseModel):
    costsheet_i_ds: Annotated[
        Optional[List[str]], pydantic.Field(alias="costsheetIDs")
    ] = None
    r"""CostsheetIDs allows filtering by specific costsheet IDs"""

    environment_id: Annotated[Optional[str], pydantic.Field(alias="environmentID")] = (
        None
    )
    r"""EnvironmentID filters by specific environment ID"""

    filters: Optional[List[FilterCondition]] = None
    r"""Filters contains custom filtering conditions"""

    lookup_key: Annotated[Optional[str], pydantic.Field(alias="lookupKey")] = None
    r"""LookupKey filters by lookup key"""

    name: Optional[str] = None
    r"""Name filters by costsheet name"""

    query_filter: Annotated[
        Optional[QueryFilter], pydantic.Field(alias="queryFilter")
    ] = None

    sort: Optional[List[SortCondition]] = None
    r"""Sort specifies result ordering preferences"""

    status: Optional[Status] = None

    tenant_id: Annotated[Optional[str], pydantic.Field(alias="tenantID")] = None
    r"""TenantID filters by specific tenant ID"""

    time_range_filter: Annotated[
        Optional[TimeRangeFilter], pydantic.Field(alias="timeRangeFilter")
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "costsheetIDs",
                "environmentID",
                "filters",
                "lookupKey",
                "name",
                "queryFilter",
                "sort",
                "status",
                "tenantID",
                "timeRangeFilter",
            ]
        )
        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


try:
    CostsheetFilter.model_rebuild()
except NameError:
    pass
