"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: fbbf7428328c

from __future__ import annotations
from .processstatus import ProcessStatus
from datetime import datetime
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import Any, Dict
from typing_extensions import Annotated, NotRequired, TypedDict


class DocumentTypedDict(TypedDict):
    id: str
    library_id: str
    hash: Nullable[str]
    mime_type: Nullable[str]
    extension: Nullable[str]
    size: Nullable[int]
    name: str
    created_at: datetime
    process_status: ProcessStatus
    uploaded_by_id: Nullable[str]
    uploaded_by_type: str
    processing_status: str
    tokens_processing_total: int
    summary: NotRequired[Nullable[str]]
    last_processed_at: NotRequired[Nullable[datetime]]
    number_of_pages: NotRequired[Nullable[int]]
    tokens_processing_main_content: NotRequired[Nullable[int]]
    tokens_processing_summary: NotRequired[Nullable[int]]
    url: NotRequired[Nullable[str]]
    attributes: NotRequired[Nullable[Dict[str, Any]]]
    expires_at: NotRequired[Nullable[datetime]]
    r"""If set, the document will be automatically deleted after this date."""


class Document(BaseModel):
    id: str

    library_id: str

    hash: Annotated[
        Nullable[str],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
        ),
    ]

    mime_type: Nullable[str]

    extension: Nullable[str]

    size: Nullable[int]

    name: str

    created_at: datetime

    process_status: ProcessStatus

    uploaded_by_id: Nullable[str]

    uploaded_by_type: str

    processing_status: Annotated[
        str,
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
        ),
    ]

    tokens_processing_total: int

    summary: OptionalNullable[str] = UNSET

    last_processed_at: OptionalNullable[datetime] = UNSET

    number_of_pages: OptionalNullable[int] = UNSET

    tokens_processing_main_content: Annotated[
        OptionalNullable[int],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
        ),
    ] = UNSET

    tokens_processing_summary: Annotated[
        OptionalNullable[int],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This will be removed in a future release, please migrate away from it as soon as possible."
        ),
    ] = UNSET

    url: OptionalNullable[str] = UNSET

    attributes: OptionalNullable[Dict[str, Any]] = UNSET

    expires_at: OptionalNullable[datetime] = UNSET
    r"""If set, the document will be automatically deleted after this date."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "summary",
                "last_processed_at",
                "number_of_pages",
                "tokens_processing_main_content",
                "tokens_processing_summary",
                "url",
                "attributes",
                "expires_at",
            ]
        )
        nullable_fields = set(
            [
                "hash",
                "mime_type",
                "extension",
                "size",
                "summary",
                "last_processed_at",
                "number_of_pages",
                "uploaded_by_id",
                "tokens_processing_main_content",
                "tokens_processing_summary",
                "url",
                "attributes",
                "expires_at",
            ]
        )
        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
