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

from __future__ import annotations
from .thread import Thread, ThreadTypedDict
from attio.types import BaseModel, UNSET_SENTINEL
from attio.utils import FieldMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class GetV2ThreadsRequestTypedDict(TypedDict):
    record_id: NotRequired[str]
    object: NotRequired[str]
    entry_id: NotRequired[str]
    list_id: NotRequired[str]
    limit: NotRequired[int]
    offset: NotRequired[int]


class GetV2ThreadsRequest(BaseModel):
    record_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    object: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    entry_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    list_id: Annotated[
        Optional[str],
        pydantic.Field(alias="list"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["record_id", "object", "entry_id", "list_id", "limit", "offset"]
        )
        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


class GetV2ThreadsResponseTypedDict(TypedDict):
    r"""Success"""

    data: List[ThreadTypedDict]


class GetV2ThreadsResponse(BaseModel):
    r"""Success"""

    data: List[Thread]
