"""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 .folder import Folder, FolderTypedDict
from attio.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from attio.utils import get_discriminator
from pydantic import Discriminator, Tag, model_serializer
from typing import Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


PostV2FilesStorageProvider2 = Literal[
    "dropbox",
    "box",
    "google-drive",
    "microsoft-onedrive",
]
r"""The external storage provider."""


FileTypeConnectedFile = Literal["connected-file",]
r"""Creates a connected file entry."""


class PostV2FilesConnectedFileTypedDict(TypedDict):
    object: str
    r"""The object slug or ID."""
    record_id: str
    r"""The ID of the record to create the file entry on."""
    storage_provider: PostV2FilesStorageProvider2
    r"""The external storage provider."""
    external_provider_file_id: str
    r"""The ID of the file or folder in the external storage provider."""
    file_type: FileTypeConnectedFile
    r"""Creates a connected file entry."""
    microsoft_drive_id: NotRequired[Nullable[str]]
    r"""Microsoft drive ID. Only used when `storage_provider` is `microsoft-onedrive`."""


class PostV2FilesConnectedFile(BaseModel):
    object: str
    r"""The object slug or ID."""

    record_id: str
    r"""The ID of the record to create the file entry on."""

    storage_provider: PostV2FilesStorageProvider2
    r"""The external storage provider."""

    external_provider_file_id: str
    r"""The ID of the file or folder in the external storage provider."""

    file_type: FileTypeConnectedFile
    r"""Creates a connected file entry."""

    microsoft_drive_id: OptionalNullable[str] = UNSET
    r"""Microsoft drive ID. Only used when `storage_provider` is `microsoft-onedrive`."""

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


PostV2FilesStorageProvider1 = Literal[
    "dropbox",
    "box",
    "google-drive",
    "microsoft-onedrive",
]
r"""The external storage provider."""


FileTypeConnectedFolder = Literal["connected-folder",]
r"""Creates a connected folder entry."""


class PostV2FilesConnectedFolderTypedDict(TypedDict):
    object: str
    r"""The object slug or ID."""
    record_id: str
    r"""The ID of the record to create the file entry on."""
    storage_provider: PostV2FilesStorageProvider1
    r"""The external storage provider."""
    external_provider_file_id: str
    r"""The ID of the file or folder in the external storage provider."""
    file_type: FileTypeConnectedFolder
    r"""Creates a connected folder entry."""
    microsoft_drive_id: NotRequired[Nullable[str]]
    r"""Microsoft drive ID. Only used when `storage_provider` is `microsoft-onedrive`."""


class PostV2FilesConnectedFolder(BaseModel):
    object: str
    r"""The object slug or ID."""

    record_id: str
    r"""The ID of the record to create the file entry on."""

    storage_provider: PostV2FilesStorageProvider1
    r"""The external storage provider."""

    external_provider_file_id: str
    r"""The ID of the file or folder in the external storage provider."""

    file_type: FileTypeConnectedFolder
    r"""Creates a connected folder entry."""

    microsoft_drive_id: OptionalNullable[str] = UNSET
    r"""Microsoft drive ID. Only used when `storage_provider` is `microsoft-onedrive`."""

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


PostV2FilesFileTypeFolder = Literal["folder",]
r"""Creates a native Attio folder entry."""


class PostV2FilesFolderTypedDict(TypedDict):
    object: str
    r"""The object slug or ID."""
    record_id: str
    r"""The ID of the record to create the file entry on."""
    file_type: PostV2FilesFileTypeFolder
    r"""Creates a native Attio folder entry."""
    name: str
    r"""The folder name."""
    parent_folder_id: NotRequired[str]
    r"""Optional parent folder ID. Omit to create a top-level folder."""


class PostV2FilesFolder(BaseModel):
    object: str
    r"""The object slug or ID."""

    record_id: str
    r"""The ID of the record to create the file entry on."""

    file_type: PostV2FilesFileTypeFolder
    r"""Creates a native Attio folder entry."""

    name: str
    r"""The folder name."""

    parent_folder_id: Optional[str] = None
    r"""Optional parent folder ID. Omit to create a top-level folder."""

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


PostV2FilesRequestTypedDict = TypeAliasType(
    "PostV2FilesRequestTypedDict",
    Union[
        PostV2FilesFolderTypedDict,
        PostV2FilesConnectedFolderTypedDict,
        PostV2FilesConnectedFileTypedDict,
    ],
)


PostV2FilesRequest = Annotated[
    Union[
        Annotated[PostV2FilesFolder, Tag("folder")],
        Annotated[PostV2FilesConnectedFolder, Tag("connected-folder")],
        Annotated[PostV2FilesConnectedFile, Tag("connected-file")],
    ],
    Discriminator(lambda m: get_discriminator(m, "file_type", "file_type")),
]


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


PostV2FilesData = Annotated[
    Union[
        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 PostV2FilesResponseTypedDict(TypedDict):
    r"""Success"""

    data: PostV2FilesDataTypedDict


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

    data: PostV2FilesData
