# 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 pydantic.v1 import Field, StrictInt, conlist

from earnix_elevate.clients.data.models.source_node_definition import (
    SourceNodeDefinition,
)
from earnix_elevate.clients.data.models.update_dataset_node_request import (
    UpdateDatasetNodeRequest,
)


class UpdateDatasetRecipeNodeRequest(UpdateDatasetNodeRequest):
    """
    `UpdateDatasetRecipeNodeRequest`

    Updates the configuration of an existing recipe node within the transformation graph. This allows modification of node properties. To update recipe code, use PUT /v1/recipes/{recipe-id}/versions/{version-number}.
    """

    source_node_definitions: conlist(
        SourceNodeDefinition, max_items=10, min_items=1
    ) = Field(
        default=...,
        alias="sourceNodeDefinitions",
        description="Source nodes with aliases. Size must equal recipeVersion.aliases.size().",
    )
    recipe_id: StrictInt = Field(
        default=...,
        alias="recipeId",
        description="ID of the existing recipe to reference in the transformation graph (optional, only needed when switching to a different recipe)",
    )
    recipe_version_number: StrictInt = Field(default=..., alias="recipeVersionNumber")
    __properties = [
        "nodeType",
        "datasetId",
        "id",
        "lockVersion",
        "sourceNodeDefinitions",
        "recipeId",
        "recipeVersionNumber",
    ]

    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) -> UpdateDatasetRecipeNodeRequest:
        """Create an instance of UpdateDatasetRecipeNodeRequest 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 each item in source_node_definitions (list)
        _items = []
        if self.source_node_definitions:
            for _item in self.source_node_definitions:
                if _item:
                    _items.append(_item.to_dict())
            _dict["sourceNodeDefinitions"] = _items
        return _dict

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

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

        _obj = UpdateDatasetRecipeNodeRequest.parse_obj(
            {
                "node_type": obj.get("nodeType"),
                "dataset_id": obj.get("datasetId"),
                "id": obj.get("id"),
                "lock_version": obj.get("lockVersion"),
                "source_node_definitions": [
                    SourceNodeDefinition.from_dict(_item)
                    for _item in obj.get("sourceNodeDefinitions")
                ]
                if obj.get("sourceNodeDefinitions") is not None
                else None,
                "recipe_id": obj.get("recipeId"),
                "recipe_version_number": obj.get("recipeVersionNumber"),
            }
        )
        return _obj
