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

from __future__ import annotations
from .v3_auditlogs_actor import V3AuditLogsActor, V3AuditLogsActorTypedDict
from .v3_auditlogs_team import V3AuditLogsTeam, V3AuditLogsTeamTypedDict
from datetime import date
import pydantic
from pydantic import model_serializer
from squadcast.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from typing import List
from typing_extensions import Annotated, NotRequired, TypedDict


class V3AuditLogsFiltersTypedDict(TypedDict):
    r"""Represents filters used in audit log queries"""

    start_date: date
    end_date: date
    resource: NotRequired[Nullable[List[str]]]
    action: NotRequired[Nullable[List[str]]]
    actor: NotRequired[Nullable[List[V3AuditLogsActorTypedDict]]]
    team: NotRequired[Nullable[List[V3AuditLogsTeamTypedDict]]]
    client: NotRequired[Nullable[List[str]]]


class V3AuditLogsFilters(BaseModel):
    r"""Represents filters used in audit log queries"""

    start_date: Annotated[date, pydantic.Field(alias="startDate")]

    end_date: Annotated[date, pydantic.Field(alias="endDate")]

    resource: OptionalNullable[List[str]] = UNSET

    action: OptionalNullable[List[str]] = UNSET

    actor: OptionalNullable[List[V3AuditLogsActor]] = UNSET

    team: OptionalNullable[List[V3AuditLogsTeam]] = UNSET

    client: OptionalNullable[List[str]] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["resource", "action", "actor", "team", "client"])
        nullable_fields = set(["resource", "action", "actor", "team", "client"])
        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))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m


try:
    V3AuditLogsFilters.model_rebuild()
except NameError:
    pass
