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

from __future__ import annotations
from enum import Enum
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 InitImageType(str, Enum):
    r"""Type indicating whether the init image is uploaded or generated."""

    GENERATED = "GENERATED"
    UPLOADED = "UPLOADED"


class StrengthType(str, Enum):
    r"""Strength type for the controlnet. Can only be used for Style, Character and Content Reference controlnets."""

    LOW = "Low"
    MID = "Mid"
    HIGH = "High"
    ULTRA = "Ultra"
    MAX = "Max"


class ControlnetInputTypedDict(TypedDict):
    init_image_id: NotRequired[str]
    r"""The ID of the init image"""
    init_image_type: NotRequired[InitImageType]
    r"""Type indicating whether the init image is uploaded or generated."""
    preprocessor_id: NotRequired[float]
    r"""ID of the controlnet. A list of compatible IDs can be found in our guides."""
    strength_type: NotRequired[Nullable[StrengthType]]
    r"""Strength type for the controlnet. Can only be used for Style, Character and Content Reference controlnets."""
    weight: NotRequired[Nullable[float]]
    r"""Weight for the controlnet"""


class ControlnetInput(BaseModel):
    init_image_id: Annotated[Optional[str], pydantic.Field(alias="initImageId")] = None
    r"""The ID of the init image"""

    init_image_type: Annotated[
        Optional[InitImageType], pydantic.Field(alias="initImageType")
    ] = None
    r"""Type indicating whether the init image is uploaded or generated."""

    preprocessor_id: Annotated[
        Optional[float], pydantic.Field(alias="preprocessorId")
    ] = None
    r"""ID of the controlnet. A list of compatible IDs can be found in our guides."""

    strength_type: Annotated[
        OptionalNullable[StrengthType], pydantic.Field(alias="strengthType")
    ] = UNSET
    r"""Strength type for the controlnet. Can only be used for Style, Character and Content Reference controlnets."""

    weight: OptionalNullable[float] = UNSET
    r"""Weight for the controlnet"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "initImageId",
            "initImageType",
            "preprocessorId",
            "strengthType",
            "weight",
        ]
        nullable_fields = ["strengthType", "weight"]
        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
