# coding: utf-8

"""
    Platform API

    _OpenAPI specification for the **Platform API** of **Helix**, the nomination platform of ElecLink_  ---  Additional documentation available in the API's [GitHub repository](https://github.com/eleclink-helix/platform-api) 

    The version of the OpenAPI document: 1.1.0
    Contact: team.eleclink@eleclink.co.uk
    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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from helix_platform_api_public_client.models.business_process_step_attempt import BusinessProcessStepAttempt
from helix_platform_api_public_client.models.business_process_step_logic_type import BusinessProcessStepLogicType
from helix_platform_api_public_client.models.business_process_step_type import BusinessProcessStepType
from helix_platform_api_public_client.models.data_flow_direction import DataFlowDirection
from helix_platform_api_public_client.models.interface import Interface
from typing import Optional, Set
from typing_extensions import Self

class BusinessProcessStepBlock(BaseModel):
    """
    BusinessProcessStepBlock
    """ # noqa: E501
    block_type: StrictStr = Field(alias="blockType")
    step_type: BusinessProcessStepType = Field(alias="stepType")
    logic_type: BusinessProcessStepLogicType = Field(alias="logicType")
    data_flow_direction: Optional[DataFlowDirection] = Field(default=None, alias="dataFlowDirection")
    interface: Optional[Interface] = None
    id: Optional[StrictStr] = Field(default=None, description="Unique identifier for the record in UUID4 format")
    resolvable: StrictBool
    rerunnable: StrictBool
    attempts: List[BusinessProcessStepAttempt]
    data_flow_version_id: Optional[StrictStr] = Field(default=None, description="Unique identifier for the record in UUID4 format", alias="dataFlowVersionId")
    __properties: ClassVar[List[str]] = ["blockType", "stepType", "logicType", "dataFlowDirection", "interface", "id", "resolvable", "rerunnable", "attempts", "dataFlowVersionId"]

    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 BusinessProcessStepBlock 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 step_type
        if self.step_type:
            _dict['stepType'] = self.step_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of interface
        if self.interface:
            _dict['interface'] = self.interface.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in attempts (list)
        _items = []
        if self.attempts:
            for _item_attempts in self.attempts:
                if _item_attempts:
                    _items.append(_item_attempts.to_dict())
            _dict['attempts'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "blockType": obj.get("blockType"),
            "stepType": BusinessProcessStepType.from_dict(obj["stepType"]) if obj.get("stepType") is not None else None,
            "logicType": obj.get("logicType"),
            "dataFlowDirection": obj.get("dataFlowDirection"),
            "interface": Interface.from_dict(obj["interface"]) if obj.get("interface") is not None else None,
            "id": obj.get("id"),
            "resolvable": obj.get("resolvable"),
            "rerunnable": obj.get("rerunnable"),
            "attempts": [BusinessProcessStepAttempt.from_dict(_item) for _item in obj["attempts"]] if obj.get("attempts") is not None else None,
            "dataFlowVersionId": obj.get("dataFlowVersionId")
        })
        return _obj


