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

from __future__ import annotations
from factify.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from factify.utils import FieldMetadata, MultipartFormMetadata
import io
import pydantic
from pydantic import model_serializer
from typing import IO, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


class CreateVersionRequestPayloadTypedDict(TypedDict):
    file_name: str
    content: Union[bytes, IO[bytes], io.BufferedReader]
    content_type: NotRequired[str]


class CreateVersionRequestPayload(BaseModel):
    file_name: Annotated[
        str, pydantic.Field(alias="fileName"), FieldMetadata(multipart=True)
    ]

    content: Annotated[
        Union[bytes, IO[bytes], io.BufferedReader],
        pydantic.Field(alias=""),
        FieldMetadata(multipart=MultipartFormMetadata(content=True)),
    ]

    content_type: Annotated[
        Optional[str],
        pydantic.Field(alias="Content-Type"),
        FieldMetadata(multipart=True),
    ] = None

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


class CreateVersionRequestTypedDict(TypedDict):
    r"""CreateVersionRequest contains the file and metadata for creating a version."""

    payload: CreateVersionRequestPayloadTypedDict
    r"""PDF file for new version"""
    description: NotRequired[Nullable[str]]
    r"""Description of changes in this version."""
    title: NotRequired[Nullable[str]]
    r"""Optional version title."""


class CreateVersionRequest(BaseModel):
    r"""CreateVersionRequest contains the file and metadata for creating a version."""

    payload: Annotated[
        CreateVersionRequestPayload,
        FieldMetadata(multipart=MultipartFormMetadata(file=True)),
    ]
    r"""PDF file for new version"""

    description: Annotated[OptionalNullable[str], FieldMetadata(multipart=True)] = UNSET
    r"""Description of changes in this version."""

    title: Annotated[OptionalNullable[str], FieldMetadata(multipart=True)] = UNSET
    r"""Optional version title."""

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