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

from __future__ import annotations
from .ocrpageobject import OCRPageObject, OCRPageObjectTypedDict
from .ocrusageinfo import OCRUsageInfo, OCRUsageInfoTypedDict
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List
from typing_extensions import NotRequired, TypedDict


class OCRResponseTypedDict(TypedDict):
    pages: List[OCRPageObjectTypedDict]
    r"""List of OCR info for pages."""
    model: str
    r"""The model used to generate the OCR."""
    usage_info: OCRUsageInfoTypedDict
    document_annotation: NotRequired[Nullable[str]]
    r"""Formatted response in the request_format if provided in json str"""


class OCRResponse(BaseModel):
    pages: List[OCRPageObject]
    r"""List of OCR info for pages."""

    model: str
    r"""The model used to generate the OCR."""

    usage_info: OCRUsageInfo

    document_annotation: OptionalNullable[str] = UNSET
    r"""Formatted response in the request_format if provided in json str"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["document_annotation"])
        nullable_fields = set(["document_annotation"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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
