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

from __future__ import annotations

from typing import Literal

from pydantic import model_serializer
from typing_extensions import NotRequired, TypedDict

from friendli.types import UNSET, UNSET_SENTINEL, BaseModel, Nullable, OptionalNullable

DedicatedImageGenerationBodyResponseFormat = Literal["url", "raw", "png", "jpeg", "jpg"]
r"""The format in which the generated image(s) will be returned. One of `url(default)`, `raw`, `png`, `jpeg`, and `jpg`."""


class DedicatedImageGenerationBodyTypedDict(TypedDict):
    model: str
    r"""ID of target endpoint. If you want to send request to specific adapter, use the format \"YOUR_ENDPOINT_ID:YOUR_ADAPTER_ROUTE\". Otherwise, you can just use \"YOUR_ENDPOINT_ID\" alone."""
    prompt: str
    r"""A text description of the desired image(s)."""
    num_inference_steps: NotRequired[Nullable[int]]
    r"""The number of inference steps to use during image generation. Supported range: [1, 10]. Defaults to 4."""
    response_format: NotRequired[Nullable[DedicatedImageGenerationBodyResponseFormat]]
    r"""The format in which the generated image(s) will be returned. One of `url(default)`, `raw`, `png`, `jpeg`, and `jpg`."""
    seed: NotRequired[Nullable[int]]
    r"""The seed to use for image generation."""


class DedicatedImageGenerationBody(BaseModel):
    model: str
    r"""ID of target endpoint. If you want to send request to specific adapter, use the format \"YOUR_ENDPOINT_ID:YOUR_ADAPTER_ROUTE\". Otherwise, you can just use \"YOUR_ENDPOINT_ID\" alone."""

    prompt: str
    r"""A text description of the desired image(s)."""

    num_inference_steps: OptionalNullable[int] = 4
    r"""The number of inference steps to use during image generation. Supported range: [1, 10]. Defaults to 4."""

    response_format: OptionalNullable[DedicatedImageGenerationBodyResponseFormat] = (
        "url"
    )
    r"""The format in which the generated image(s) will be returned. One of `url(default)`, `raw`, `png`, `jpeg`, and `jpg`."""

    seed: OptionalNullable[int] = UNSET
    r"""The seed to use for image generation."""

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