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

from __future__ import annotations
from .imageinput import ImageInput, ImageInputTypedDict
from friendli.core.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List, Literal, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict

ContainerImageEditBodyImageTypedDict = TypeAliasType(
    "ContainerImageEditBodyImageTypedDict",
    Union[ImageInputTypedDict, List[ImageInputTypedDict]],
)
"The image(s) to edit. Must be in a supported image format."
ContainerImageEditBodyImage = TypeAliasType(
    "ContainerImageEditBodyImage", Union[ImageInput, List[ImageInput]]
)
"The image(s) to edit. Must be in a supported image format."
ContainerImageEditBodyResponseFormat = Literal["raw", "jpeg"]


class ContainerImageEditBodyTypedDict(TypedDict):
    image: ContainerImageEditBodyImageTypedDict
    "The image(s) to edit. Must be in a supported image format."
    prompt: str
    "A text description of the desired image."
    model: NotRequired[Nullable[str]]
    "Routes the request to a specific adapter."
    num_inference_steps: NotRequired[int]
    "The number of inference steps to use during image generation. Defaults to 20. Supported range: [1, 50]."
    guidance_scale: NotRequired[float]
    "Adjusts the alignment of the generated image with the input prompt. Higher values (e.g., 8-10) make the output more faithful to the prompt, while lower values (e.g., 1-5) encourage more creative freedom. Defaults to 0. This parameter may be irrelevant for certain models, such as `FLUX.Schnell`."
    seed: NotRequired[Nullable[int]]
    "The seed to use for image generation."
    response_format: NotRequired[Nullable[ContainerImageEditBodyResponseFormat]]
    "The format in which the generated image will be returned. One of `raw` and `jpeg`."


class ContainerImageEditBody(BaseModel):
    image: ContainerImageEditBodyImage
    "The image(s) to edit. Must be in a supported image format."
    prompt: str
    "A text description of the desired image."
    model: OptionalNullable[str] = UNSET
    "Routes the request to a specific adapter."
    num_inference_steps: Optional[int] = 20
    "The number of inference steps to use during image generation. Defaults to 20. Supported range: [1, 50]."
    guidance_scale: Optional[float] = 0
    "Adjusts the alignment of the generated image with the input prompt. Higher values (e.g., 8-10) make the output more faithful to the prompt, while lower values (e.g., 1-5) encourage more creative freedom. Defaults to 0. This parameter may be irrelevant for certain models, such as `FLUX.Schnell`."
    seed: OptionalNullable[int] = UNSET
    "The seed to use for image generation."
    response_format: OptionalNullable[ContainerImageEditBodyResponseFormat] = UNSET
    "The format in which the generated image will be returned. One of `raw` and `jpeg`."

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "model",
            "num_inference_steps",
            "guidance_scale",
            "seed",
            "response_format",
        ]
        nullable_fields = ["model", "seed", "response_format"]
        null_default_fields = []
        serialized = handler(self)
        m = {}
        for n, f in type(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
            )
            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                k not in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val
        return m
