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

from __future__ import annotations
from attio.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Literal
from typing_extensions import NotRequired, TypedDict


class ConnectedFileIDTypedDict(TypedDict):
    workspace_id: str
    r"""The ID of the workspace the file belongs to."""
    file_id: str
    r"""The ID of the file entry."""


class ConnectedFileID(BaseModel):
    workspace_id: str
    r"""The ID of the workspace the file belongs to."""

    file_id: str
    r"""The ID of the file entry."""


ConnectedFileStorageProvider = Literal[
    "attio",
    "dropbox",
    "box",
    "google-drive",
    "microsoft-onedrive",
]
r"""The storage provider for this file entry."""


ConnectedFileType = Literal[
    "api-token",
    "workspace-member",
    "system",
    "app",
]
r"""The type of actor. [Read more information on actor types here](/docs/actors)."""


class ConnectedFileCreatedByActorTypedDict(TypedDict):
    r"""The actor that created this file entry."""

    id: NotRequired[Nullable[str]]
    r"""An ID to identify the actor."""
    type: NotRequired[Nullable[ConnectedFileType]]
    r"""The type of actor. [Read more information on actor types here](/docs/actors)."""


class ConnectedFileCreatedByActor(BaseModel):
    r"""The actor that created this file entry."""

    id: OptionalNullable[str] = UNSET
    r"""An ID to identify the actor."""

    type: OptionalNullable[ConnectedFileType] = UNSET
    r"""The type of actor. [Read more information on actor types here](/docs/actors)."""

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


ConnectedFileFileType = Literal["connected-file",]
r"""The type of file entry."""


class ConnectedFileTypedDict(TypedDict):
    id: ConnectedFileIDTypedDict
    object_id: str
    r"""The ID of the object the record belongs to."""
    object_slug: str
    r"""The slug of the object the record belongs to."""
    record_id: str
    r"""The ID of the record the file is linked to."""
    storage_provider: ConnectedFileStorageProvider
    r"""The storage provider for this file entry."""
    created_by_actor: ConnectedFileCreatedByActorTypedDict
    r"""The actor that created this file entry."""
    created_at: str
    r"""Timestamp representing when the file entry was created."""
    file_type: ConnectedFileFileType
    r"""The type of file entry."""
    external_provider_file_id: str
    r"""The file ID in the external storage provider."""
    microsoft_drive_id: Nullable[str]
    r"""Microsoft drive ID. This field is only populated for `microsoft-onedrive` entries."""


class ConnectedFile(BaseModel):
    id: ConnectedFileID

    object_id: str
    r"""The ID of the object the record belongs to."""

    object_slug: str
    r"""The slug of the object the record belongs to."""

    record_id: str
    r"""The ID of the record the file is linked to."""

    storage_provider: ConnectedFileStorageProvider
    r"""The storage provider for this file entry."""

    created_by_actor: ConnectedFileCreatedByActor
    r"""The actor that created this file entry."""

    created_at: str
    r"""Timestamp representing when the file entry was created."""

    file_type: ConnectedFileFileType
    r"""The type of file entry."""

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

    microsoft_drive_id: Nullable[str]
    r"""Microsoft drive ID. This field is only populated for `microsoft-onedrive` entries."""

    @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
