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

from __future__ import annotations
from .connected_file import ConnectedFile, ConnectedFileTypedDict
from .connected_folder import ConnectedFolder, ConnectedFolderTypedDict
from .file import File, FileTypedDict
from .folder import Folder, FolderTypedDict
from attio.types import BaseModel, Nullable, UNSET_SENTINEL
from attio.utils import FieldMetadata, QueryParamMetadata, get_discriminator
from pydantic import Discriminator, Tag, model_serializer
from typing import List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


GetV2FilesStorageProvider = Literal[
    "attio",
    "dropbox",
    "box",
    "google-drive",
    "microsoft-onedrive",
]
r"""Filter results by storage provider."""


class GetV2FilesRequestTypedDict(TypedDict):
    object: str
    record_id: str
    storage_provider: NotRequired[GetV2FilesStorageProvider]
    r"""Filter results by storage provider."""
    parent_folder_id: NotRequired[str]
    limit: NotRequired[int]
    cursor: NotRequired[str]


class GetV2FilesRequest(BaseModel):
    object: Annotated[
        str, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
    ]

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

    storage_provider: Annotated[
        Optional[GetV2FilesStorageProvider],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter results by storage provider."""

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

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["storage_provider", "parent_folder_id", "limit", "cursor"]
        )
        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


GetV2FilesDataTypedDict = TypeAliasType(
    "GetV2FilesDataTypedDict",
    Union[
        FolderTypedDict, ConnectedFileTypedDict, ConnectedFolderTypedDict, FileTypedDict
    ],
)


GetV2FilesData = Annotated[
    Union[
        Annotated[File, Tag("file")],
        Annotated[Folder, Tag("folder")],
        Annotated[ConnectedFile, Tag("connected-file")],
        Annotated[ConnectedFolder, Tag("connected-folder")],
    ],
    Discriminator(lambda m: get_discriminator(m, "file_type", "file_type")),
]


class GetV2FilesPaginationTypedDict(TypedDict):
    next_cursor: Nullable[str]


class GetV2FilesPagination(BaseModel):
    next_cursor: Nullable[str]

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        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:
                m[k] = val

        return m


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

    data: List[GetV2FilesDataTypedDict]
    pagination: GetV2FilesPaginationTypedDict


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

    data: List[GetV2FilesData]

    pagination: GetV2FilesPagination
