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

from __future__ import annotations
import httpx
from leonardo_ai_sdk.models.shared import (
    universal_upscaler_style as shared_universal_upscaler_style,
    universal_upscaler_ultra_style as shared_universal_upscaler_ultra_style,
)
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 CreateUniversalUpscalerJobRequestBodyTypedDict(TypedDict):
    r"""Query parameters are provided in the request body as a JSON object"""

    creativity_strength: NotRequired[Nullable[int]]
    r"""The creativity strength of the universal upscaler. Must be between 1 and 10."""
    detail_contrast: NotRequired[Nullable[int]]
    r"""The detail contrast of the universal upscaler. Must be between 1 and 10. Can only be used with ultraUpscaleStyle."""
    generated_image_id: NotRequired[Nullable[str]]
    r"""The ID of the generated image."""
    init_image_id: NotRequired[Nullable[str]]
    r"""The ID of the init image uploaded."""
    prompt: NotRequired[Nullable[str]]
    r"""The prompt for the universal upscaler."""
    similarity: NotRequired[Nullable[int]]
    r"""The similarity of the universal upscaler. Must be between 1 and 10. Can only be used with ultraUpscaleStyle."""
    ultra_upscale_style: NotRequired[
        Nullable[shared_universal_upscaler_ultra_style.UniversalUpscalerUltraStyle]
    ]
    r"""The ultra style to upscale images using universal upscaler with. Can not be used with upscalerStyle."""
    upscale_multiplier: NotRequired[Nullable[float]]
    r"""The upscale multiplier of the universal upscaler. Must be between 1.0 and 2.0."""
    upscaler_style: NotRequired[
        Nullable[shared_universal_upscaler_style.UniversalUpscalerStyle]
    ]
    r"""The style to upscale images using universal upscaler with. Can not be used with ultraUpscaleStyle."""
    variation_id: NotRequired[Nullable[str]]
    r"""The ID of the variation image."""


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

    creativity_strength: Annotated[
        OptionalNullable[int], pydantic.Field(alias="creativityStrength")
    ] = 5
    r"""The creativity strength of the universal upscaler. Must be between 1 and 10."""

    detail_contrast: Annotated[
        OptionalNullable[int], pydantic.Field(alias="detailContrast")
    ] = UNSET
    r"""The detail contrast of the universal upscaler. Must be between 1 and 10. Can only be used with ultraUpscaleStyle."""

    generated_image_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="generatedImageId")
    ] = UNSET
    r"""The ID of the generated image."""

    init_image_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="initImageId")
    ] = UNSET
    r"""The ID of the init image uploaded."""

    prompt: OptionalNullable[str] = UNSET
    r"""The prompt for the universal upscaler."""

    similarity: OptionalNullable[int] = UNSET
    r"""The similarity of the universal upscaler. Must be between 1 and 10. Can only be used with ultraUpscaleStyle."""

    ultra_upscale_style: Annotated[
        OptionalNullable[
            shared_universal_upscaler_ultra_style.UniversalUpscalerUltraStyle
        ],
        pydantic.Field(alias="ultraUpscaleStyle"),
    ] = UNSET
    r"""The ultra style to upscale images using universal upscaler with. Can not be used with upscalerStyle."""

    upscale_multiplier: Annotated[
        OptionalNullable[float], pydantic.Field(alias="upscaleMultiplier")
    ] = 1.5
    r"""The upscale multiplier of the universal upscaler. Must be between 1.0 and 2.0."""

    upscaler_style: Annotated[
        OptionalNullable[shared_universal_upscaler_style.UniversalUpscalerStyle],
        pydantic.Field(alias="upscalerStyle"),
    ] = shared_universal_upscaler_style.UniversalUpscalerStyle.GENERAL
    r"""The style to upscale images using universal upscaler with. Can not be used with ultraUpscaleStyle."""

    variation_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="variationId")
    ] = UNSET
    r"""The ID of the variation image."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "creativityStrength",
            "detailContrast",
            "generatedImageId",
            "initImageId",
            "prompt",
            "similarity",
            "ultraUpscaleStyle",
            "upscaleMultiplier",
            "upscalerStyle",
            "variationId",
        ]
        nullable_fields = [
            "creativityStrength",
            "detailContrast",
            "generatedImageId",
            "initImageId",
            "prompt",
            "similarity",
            "ultraUpscaleStyle",
            "upscaleMultiplier",
            "upscalerStyle",
            "variationId",
        ]
        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 UniversalUpscalerOutputTypedDict(TypedDict):
    api_credit_cost: NotRequired[Nullable[int]]
    r"""API Credits Cost for Universal Upscaler Variation. Available for Production API Users."""
    id: NotRequired[Nullable[str]]


class UniversalUpscalerOutput(BaseModel):
    api_credit_cost: Annotated[
        OptionalNullable[int], pydantic.Field(alias="apiCreditCost")
    ] = UNSET
    r"""API Credits Cost for Universal Upscaler Variation. Available for Production API Users."""

    id: OptionalNullable[str] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["apiCreditCost", "id"]
        nullable_fields = ["apiCreditCost", "id"]
        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 CreateUniversalUpscalerJobResponseBodyTypedDict(TypedDict):
    r"""Responses for POST /variations/universal-upscaler"""

    universal_upscaler: NotRequired[UniversalUpscalerOutputTypedDict]


class CreateUniversalUpscalerJobResponseBody(BaseModel):
    r"""Responses for POST /variations/universal-upscaler"""

    universal_upscaler: Annotated[
        Optional[UniversalUpscalerOutput], pydantic.Field(alias="universalUpscaler")
    ] = None


class CreateUniversalUpscalerJobResponseTypedDict(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[CreateUniversalUpscalerJobResponseBodyTypedDict]
    r"""Responses for POST /variations/universal-upscaler"""


class CreateUniversalUpscalerJobResponse(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[CreateUniversalUpscalerJobResponseBody] = None
    r"""Responses for POST /variations/universal-upscaler"""
