# 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 deep_union_pydantic_dicts, 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.
    """

    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.
    """

    checkpoint: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] Custom checkpoint to be used during image generation.
    """

    clip_skip: typing.Optional[int] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] Optionally skip later layers of the text encoder. Higher values lead to more abstract interpretations of the prompt.
    """

    controlnet: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] ControlNet to be used during image generation.
    """

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

    controlnet_early_stop: typing.Optional[float] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] If provided, indicates fraction of steps at which to stop applying controlnet. This can be used to sometimes generate better outputs.
    """

    controlnet_image: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] Controlnet image encoded in b64 string for guiding image generation. Required for controlnet engines.
    """

    controlnet_preprocess: typing.Optional[bool] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] Whether to apply automatic ControlNet preprocessing.
    """

    height: typing.Optional[int] = pydantic_v1.Field(default=None)
    """
    Integer representing the height of image to generate. None will default to 512 for SD 1.5 and 1024 for FLUX, SD3, SDXL, and SSD. Supported resolutions (w,h): FLUX=[(512, 512), (576, 1024), (640, 1536), (768, 1024), (768, 1344), (832, 1216), (896, 1152), (1024, 576), (1024, 768), (1024, 1024), (1152, 896), (1216, 832), (1344, 768), (1536, 640)], SD3=[(640, 1536), (768, 1344), (832, 1216), (896, 1152), (1024, 1024), (1152, 896), (1216, 832), (1344, 768), (1536, 640)], SDXL=[(640, 1536), (768, 1344), (832, 1216), (896, 1152), (1024, 1024), (1152, 896), (1216, 832), (1344, 768), (1536, 640)], SD1.5=[(384, 704), (448, 576), (512, 512), (512, 704), (512, 768), (512, 832), (576, 448), (576, 768), (576, 1024), (640, 512), (640, 640), (640, 768), (704, 384), (704, 1216), (768, 512), (768, 576), (768, 1024), (832, 512), (896, 896), (1024, 576), (1024, 768), (1024, 1024), (1024, 1536), (1216, 704), (1536, 1024)], SSD=[(640, 1536), (768, 1344), (832, 1216), (896, 1152), (1024, 1024), (1152, 896), (1216, 832), (1344, 768), (1536, 640)].
    """

    high_noise_frac: typing.Optional[float] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] 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.
    """

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

    init_image: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    [Not supported on FLUX] Starting point image encoded in b64 string for Image to Image generation mode.
    """

    inpaint_full_res: typing.Optional[bool] = pydantic_v1.Field(default=None)
    """
    When true, upsample 'init_image' and 'mask_image' such that a bounding box drawn around the non-black content of 'mask_image' becomes the full inpainting frame. The bounding box has the same aspect ratio as that specified by ('height', 'width') parameters.
    """

    inpaint_full_res_padding: typing.Optional[int] = pydantic_v1.Field(default=None)
    """
    When 'inpaint_full_res' is true, include a frame around the non-black mask area that is this many pixels wide. This serves as a form of context for the inpainting and may improve blending.
    """

    log_prompt: typing.Optional[bool] = pydantic_v1.Field(default=None)
    """
    OctoAI stores request prompt if True.
    """

    loras: typing.Optional[typing.Dict[str, typing.Optional[float]]] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] A dictionary of LoRAs to apply. LoRAs as keys and their weights (float) as values.
    """

    mask_image: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] b64 encoded mask image for inpainting. White area should indicate where to paint.
    """

    negative_prompt: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    [Not supported on FLUX] Text describing image traits to avoid during generation.
    """

    negative_prompt2: typing.Optional[str] = pydantic_v1.Field(alias="negative_prompt_2", default=None)
    """
    [Not supported on SD3, FLUX] Text with a high level description of things to avoid during generation. Used only by SD XL.
    """

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

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

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

    prompt2: typing.Optional[str] = pydantic_v1.Field(alias="prompt_2", default=None)
    """
    [Not supported on SD3, FLUX] Text with a high-level description of the image to generate. Used only by SD XL.
    """

    sampler: typing.Optional[Scheduler] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] Sampler name (also known as 'scheduler') to use during image generation.
    """

    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.
    """

    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.
    """

    strength: typing.Optional[float] = pydantic_v1.Field(default=None)
    """
    [Not supported on FLUX] 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] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] Pre-defined styles used to guide the output image towards a particular style. Pre-defined styles are only supported by SDXL.
    """

    textual_inversions: typing.Optional[typing.Dict[str, typing.Optional[str]]] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] A dictionary of textual inversions to be used during image generation. Textual inversions as keys and trigger words as values.
    """

    transfer_images: typing.Optional[typing.Dict[str, typing.Optional[typing.List[str]]]] = pydantic_v1.Field(
        default=None
    )
    """
    [Not supported on SD3, FLUX] A dictionary containing a mapping of trigger words to a list of sample images which demonstrate the desired object or style to transfer.
    """

    use_refiner: typing.Optional[bool] = pydantic_v1.Field(default=None)
    """
    [Not supported on SD3, FLUX] Whether to enable and apply the SDXL refiner model to the image generation.
    """

    vae: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    [Not Supported on SD3, FLUX] Custom VAE to be used during image generation.
    """

    width: typing.Optional[int] = pydantic_v1.Field(default=None)
    """
    Integer representing the width of image to generate. None will default to 512 for SD 1.5 and 1024 for FLUX, SD3, SDXL, and SSD. Supported resolutions (w,h): FLUX=[(512, 512), (576, 1024), (640, 1536), (768, 1024), (768, 1344), (832, 1216), (896, 1152), (1024, 576), (1024, 768), (1024, 1024), (1152, 896), (1216, 832), (1344, 768), (1536, 640)], SD3=[(640, 1536), (768, 1344), (832, 1216), (896, 1152), (1024, 1024), (1152, 896), (1216, 832), (1344, 768), (1536, 640)], SDXL=[(640, 1536), (768, 1344), (832, 1216), (896, 1152), (1024, 1024), (1152, 896), (1216, 832), (1344, 768), (1536, 640)], SD1.5=[(384, 704), (448, 576), (512, 512), (512, 704), (512, 768), (512, 832), (576, 448), (576, 768), (576, 1024), (640, 512), (640, 640), (640, 768), (704, 384), (704, 1216), (768, 512), (768, 576), (768, 1024), (832, 512), (896, 896), (1024, 576), (1024, 768), (1024, 1024), (1024, 1536), (1216, 704), (1536, 1024)], SSD=[(640, 1536), (768, 1344), (832, 1216), (896, 1152), (1024, 1024), (1152, 896), (1216, 832), (1344, 768), (1536, 640)].
    """

    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_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs}

        return deep_union_pydantic_dicts(
            super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none)
        )

    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}
