# coding: utf-8

"""
Earnix Elevate Data API

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

The version of the OpenAPI document: 0.0.1
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

from __future__ import annotations

import json
import pprint
from typing import Optional

from pydantic.v1 import (
    BaseModel,
    Field,
    StrictBool,
    StrictStr,
    conlist,
    constr,
    validator,
)

from earnix_elevate.clients.data.models.recipe_version import RecipeVersion


class CreateRecipeRequest(BaseModel):
    """
    `CreateRecipeRequest`

    Creates a new recipe with version 1
    """

    name: constr(strict=True, max_length=100, min_length=3) = Field(
        default=...,
        description="Name of the entity for identification and display purposes",
    )
    description: Optional[constr(strict=True, max_length=500)] = Field(
        default=None,
        description="Optional detailed description providing additional context about the entity",
    )
    tags: Optional[conlist(StrictStr, unique_items=True)] = Field(
        default=None,
        description="List of unique tags for categorizing and organizing the entity",
    )
    shared: Optional[StrictBool] = True
    language: Optional[StrictStr] = Field(
        default=None, description="Recipe language (shared across all versions)"
    )
    aliases: conlist(
        constr(strict=True, max_length=64, min_length=1), max_items=10, min_items=1
    ) = Field(
        default=...,
        description='Table aliases used in SQL code for recipe transformations. Single-source recipes have 1 alias (e.g. "CurrentTable" for backward compatibility, or any valid name). Multi-source recipes have 2-10 aliases matching table names in SQL. ',
    )
    recipe_version: RecipeVersion = Field(default=..., alias="recipeVersion")
    __properties = [
        "name",
        "description",
        "tags",
        "shared",
        "language",
        "aliases",
        "recipeVersion",
    ]

    @validator("language")
    def language_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in ("SQL",):
            raise ValueError("must be one of enum values ('SQL')")
        return value

    class Config:
        """Pydantic configuration"""

        allow_population_by_field_name = True
        validate_assignment = True

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

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

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

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True, exclude={}, exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of recipe_version
        if self.recipe_version:
            _dict["recipeVersion"] = self.recipe_version.to_dict()
        # set to None if description (nullable) is None
        # and __fields_set__ contains the field
        if self.description is None and "description" in self.__fields_set__:
            _dict["description"] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> CreateRecipeRequest:
        """Create an instance of CreateRecipeRequest from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return CreateRecipeRequest.parse_obj(obj)

        _obj = CreateRecipeRequest.parse_obj(
            {
                "name": obj.get("name"),
                "description": obj.get("description"),
                "tags": obj.get("tags"),
                "shared": obj.get("shared") if obj.get("shared") is not None else True,
                "language": obj.get("language"),
                "aliases": obj.get("aliases"),
                "recipe_version": RecipeVersion.from_dict(obj.get("recipeVersion"))
                if obj.get("recipeVersion") is not None
                else None,
            }
        )
        return _obj
