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

from __future__ import annotations
from flowai_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from flowai_sdk.utils import FieldMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing import Any, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ListValidationsValidationsGetRequestTypedDict(TypedDict):
    current_user_payload: Any
    skip: NotRequired[int]
    limit: NotRequired[int]
    sort_by: NotRequired[Nullable[str]]
    r"""Field to sort by"""
    sort_order: NotRequired[str]
    r"""Sort direction (asc or desc)"""
    test_case_id: NotRequired[Nullable[str]]
    r"""Filter by test case ID"""
    validator_id: NotRequired[Nullable[str]]
    r"""Filter by validator user ID"""
    is_accepted: NotRequired[Nullable[bool]]
    r"""Filter by acceptance status"""
    created_after: NotRequired[Nullable[str]]
    r"""Filter by creation date (ISO format)"""
    created_before: NotRequired[Nullable[str]]
    r"""Filter by creation date (ISO format)"""


class ListValidationsValidationsGetRequest(BaseModel):
    current_user_payload: Annotated[
        Any, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
    ]

    skip: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 0

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 100

    sort_by: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Field to sort by"""

    sort_order: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "asc"
    r"""Sort direction (asc or desc)"""

    test_case_id: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter by test case ID"""

    validator_id: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter by validator user ID"""

    is_accepted: Annotated[
        OptionalNullable[bool],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter by acceptance status"""

    created_after: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter by creation date (ISO format)"""

    created_before: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter by creation date (ISO format)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "skip",
            "limit",
            "sort_by",
            "sort_order",
            "test_case_id",
            "validator_id",
            "is_accepted",
            "created_after",
            "created_before",
        ]
        nullable_fields = [
            "sort_by",
            "test_case_id",
            "validator_id",
            "is_accepted",
            "created_after",
            "created_before",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
