# coding: utf-8

"""
    Picteus

    The Picteus API

    The version of the OpenAPI document: 0.12.0
    Contact: edouard@koppasoft.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from picteus_ws_client.models.generation_recipe_prompt import GenerationRecipePrompt
from typing import Optional, Set
from typing_extensions import Self

class GenerationRecipe(BaseModel):
    """
    The image generation recipe
    """ # noqa: E501
    schema_version: Union[Annotated[float, Field(le=1, strict=True, ge=1)], Annotated[int, Field(le=1, strict=True, ge=1)]] = Field(description="The version of the schema the hereby recipe complies to", alias="schemaVersion")
    id: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=64)]] = Field(default=None, description="The identifier of the recipe instance")
    url: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=4096)]] = Field(default=None, description="The URL of the recipe instance")
    model_tags: List[Annotated[str, Field(min_length=1, strict=True, max_length=4096)]] = Field(description="The tags of the model generators", alias="modelTags")
    software: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=128)]] = Field(default=None, description="The software that ran the generation")
    input_assets: Optional[List[Annotated[str, Field(min_length=1, strict=True, max_length=4096)]]] = Field(default=None, description="The identifiers or URLs of the input assets", alias="inputAssets")
    aspect_ratio: Optional[Union[Annotated[float, Field(strict=True, ge=0)], Annotated[int, Field(strict=True, ge=0)]]] = Field(default=None, description="The required image aspect ratio, i.e. the result of its width by its height", alias="aspectRatio")
    prompt: GenerationRecipePrompt
    __properties: ClassVar[List[str]] = ["schemaVersion", "id", "url", "modelTags", "software", "inputAssets", "aspectRatio", "prompt"]

    @field_validator('url')
    def url_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^(https?:\/\/|\/?)[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\/%=~_|]+$", value):
            raise ValueError(r"must validate the regular expression /^(https?:\/\/|\/?)[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\/%=~_|]+$/")
        return value

    @field_validator('software')
    def software_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^(([a-z0-9A-Z-_.]{1,})\/)?([a-z0-9A-Z-_.]{1,})(:([a-z0-9A-Z-_.]{1,}))?$", value):
            raise ValueError(r"must validate the regular expression /^(([a-z0-9A-Z-_.]{1,})\/)?([a-z0-9A-Z-_.]{1,})(:([a-z0-9A-Z-_.]{1,}))?$/")
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of GenerationRecipe from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of prompt
        if self.prompt:
            _dict['prompt'] = self.prompt.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of GenerationRecipe from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "schemaVersion": obj.get("schemaVersion"),
            "id": obj.get("id"),
            "url": obj.get("url"),
            "modelTags": obj.get("modelTags"),
            "software": obj.get("software"),
            "inputAssets": obj.get("inputAssets"),
            "aspectRatio": obj.get("aspectRatio"),
            "prompt": GenerationRecipePrompt.from_dict(obj["prompt"]) if obj.get("prompt") is not None else None
        })
        return _obj


