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

from __future__ import annotations
import httpx
from leonardo_ai_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class UploadCanvasInitImageRequestBodyTypedDict(TypedDict):
    r"""Query parameters provided in the request body as a JSON object"""

    init_extension: str
    r"""Has to be png, jpg, jpeg, or webp."""
    mask_extension: str
    r"""Has to be png, jpg, jpeg, or webp."""


class UploadCanvasInitImageRequestBody(BaseModel):
    r"""Query parameters provided in the request body as a JSON object"""

    init_extension: Annotated[str, pydantic.Field(alias="initExtension")]
    r"""Has to be png, jpg, jpeg, or webp."""

    mask_extension: Annotated[str, pydantic.Field(alias="maskExtension")]
    r"""Has to be png, jpg, jpeg, or webp."""


class CanvasInitImageUploadOutputTypedDict(TypedDict):
    init_fields: NotRequired[Nullable[str]]
    init_image_id: NotRequired[Nullable[str]]
    init_key: NotRequired[Nullable[str]]
    init_url: NotRequired[Nullable[str]]
    mask_fields: NotRequired[Nullable[str]]
    mask_image_id: NotRequired[Nullable[str]]
    mask_key: NotRequired[Nullable[str]]
    mask_url: NotRequired[Nullable[str]]


class CanvasInitImageUploadOutput(BaseModel):
    init_fields: Annotated[
        OptionalNullable[str], pydantic.Field(alias="initFields")
    ] = UNSET

    init_image_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="initImageId")
    ] = UNSET

    init_key: Annotated[OptionalNullable[str], pydantic.Field(alias="initKey")] = UNSET

    init_url: Annotated[OptionalNullable[str], pydantic.Field(alias="initUrl")] = UNSET

    mask_fields: Annotated[
        OptionalNullable[str], pydantic.Field(alias="maskFields")
    ] = UNSET

    mask_image_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="maskImageId")
    ] = UNSET

    mask_key: Annotated[OptionalNullable[str], pydantic.Field(alias="maskKey")] = UNSET

    mask_url: Annotated[OptionalNullable[str], pydantic.Field(alias="maskUrl")] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "initFields",
            "initImageId",
            "initKey",
            "initUrl",
            "maskFields",
            "maskImageId",
            "maskKey",
            "maskUrl",
        ]
        nullable_fields = [
            "initFields",
            "initImageId",
            "initKey",
            "initUrl",
            "maskFields",
            "maskImageId",
            "maskKey",
            "maskUrl",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class UploadCanvasInitImageResponseBodyTypedDict(TypedDict):
    r"""Responses for POST /canvas-init-image"""

    upload_canvas_init_image: NotRequired[
        Nullable[CanvasInitImageUploadOutputTypedDict]
    ]


class UploadCanvasInitImageResponseBody(BaseModel):
    r"""Responses for POST /canvas-init-image"""

    upload_canvas_init_image: Annotated[
        OptionalNullable[CanvasInitImageUploadOutput],
        pydantic.Field(alias="uploadCanvasInitImage"),
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["uploadCanvasInitImage"]
        nullable_fields = ["uploadCanvasInitImage"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class UploadCanvasInitImageResponseTypedDict(TypedDict):
    content_type: str
    r"""HTTP response content type for this operation"""
    status_code: int
    r"""HTTP response status code for this operation"""
    raw_response: httpx.Response
    r"""Raw HTTP response; suitable for custom response parsing"""
    object: NotRequired[UploadCanvasInitImageResponseBodyTypedDict]
    r"""Responses for POST /canvas-init-image"""


class UploadCanvasInitImageResponse(BaseModel):
    content_type: str
    r"""HTTP response content type for this operation"""

    status_code: int
    r"""HTTP response status code for this operation"""

    raw_response: httpx.Response
    r"""Raw HTTP response; suitable for custom response parsing"""

    object: Optional[UploadCanvasInitImageResponseBody] = None
    r"""Responses for POST /canvas-init-image"""
