# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ...core.datetime_utils import serialize_datetime
from ...core.pydantic_utilities import pydantic_v1
from .image_encoding import ImageEncoding
from .image_generation_request_seed import ImageGenerationRequestSeed
from .scheduler import Scheduler
from .sdxl_styles import SdxlStyles


class ImageGenerationRequest(pydantic_v1.BaseModel):
    """
    Generate one or more images based on the given parameters.
    """

    prompt: str = pydantic_v1.Field()
    """
    Text describing the image content to generate.
    """

    prompt2: typing.Optional[str] = pydantic_v1.Field(alias="prompt_2", default=None)
    negative_prompt: typing.Optional[str] = None
    negative_prompt2: typing.Optional[str] = pydantic_v1.Field(alias="negative_prompt_2", default=None)
    checkpoint: typing.Optional[str] = None
    controlnet: typing.Optional[str] = None
    vae: typing.Optional[str] = None
    textual_inversions: typing.Optional[typing.Dict[str, typing.Optional[str]]] = None
    loras: typing.Optional[typing.Dict[str, typing.Optional[float]]] = None
    sampler: typing.Optional[Scheduler] = pydantic_v1.Field(default=None)
    """
    Sampler name (also known as 'scheduler') to use during image generation.
    """

    height: typing.Optional[int] = None
    width: typing.Optional[int] = None
    cfg_scale: typing.Optional[float] = pydantic_v1.Field(default=None)
    """
    Floating-point number represeting how closely to adhere to prompt description. Must be a positive number no greater than 50.0.
    """

    steps: typing.Optional[int] = pydantic_v1.Field(default=None)
    """
    Integer repreenting how many steps of diffusion to run. Must be greater than 0 and less than or equal to 200.
    """

    num_images: typing.Optional[int] = pydantic_v1.Field(default=None)
    """
    Integer representing how many output images to generate with a single prompt/configuration.
    """

    seed: typing.Optional[ImageGenerationRequestSeed] = pydantic_v1.Field(default=None)
    """
    Integer number or list of integers representing the seeds of random generators. Fixing random seed is useful when attempting to generate a specific image. Must be greater than 0 and less than 2^32.
    """

    controlnet_image: typing.Optional[str] = None
    init_image: typing.Optional[str] = None
    mask_image: typing.Optional[str] = None
    strength: typing.Optional[float] = pydantic_v1.Field(default=None)
    """
    Floating-point number indicating how much creative the Image to Image generation mode should be. Must be greater than 0 and less than or equal to 1.0.
    """

    style_preset: typing.Optional[SdxlStyles] = None
    use_refiner: typing.Optional[bool] = pydantic_v1.Field(default=None)
    """
    Whether to enable and apply the SDXL refiner model to the image generation.
    """

    high_noise_frac: typing.Optional[float] = pydantic_v1.Field(default=None)
    """
    Floating-point number that defines the fraction of steps to perform with the base model. Used only by SD XL. Must be greater than or equal to 0.0 and less than or equal to 1.0.
    """

    controlnet_conditioning_scale: typing.Optional[float] = pydantic_v1.Field(default=None)
    """
    How strong the effect of the controlnet should be.
    """

    controlnet_early_stop: typing.Optional[float] = None
    controlnet_preprocess: typing.Optional[bool] = pydantic_v1.Field(default=None)
    """
    Whether to apply automatic ControlNet preprocessing.
    """

    clip_skip: typing.Optional[int] = None
    outpainting: typing.Optional[bool] = pydantic_v1.Field(default=None)
    """
    Whether the request requires outpainting or not. If so, special preprocessing is applied for better results.
    """

    image_encoding: typing.Optional[ImageEncoding] = pydantic_v1.Field(default=None)
    """
    Define which encoding process should be applied before returning the generated image(s).
    """

    transfer_images: typing.Optional[typing.Dict[str, typing.Optional[typing.List[str]]]] = None

    def json(self, **kwargs: typing.Any) -> str:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().json(**kwargs_with_defaults)

    def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().dict(**kwargs_with_defaults)

    class Config:
        frozen = True
        smart_union = True
        allow_population_by_field_name = True
        populate_by_name = True
        extra = pydantic_v1.Extra.allow
        json_encoders = {dt.datetime: serialize_datetime}
