"""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,
)
from pydantic import model_serializer
from typing import Any, Dict
from typing_extensions import 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]]]


class Document(BaseModel):
    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: OptionalNullable[str] = UNSET

    last_processed_at: OptionalNullable[datetime] = UNSET

    number_of_pages: OptionalNullable[int] = UNSET

    tokens_processing_main_content: OptionalNullable[int] = UNSET

    tokens_processing_summary: OptionalNullable[int] = UNSET

    url: OptionalNullable[str] = UNSET

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

    @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",
            ]
        )
        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",
            ]
        )
        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
