# coding: utf-8

"""
    Twenty Api

    Twenty is a customer relationship management (CRM) platform designed to help businesses manage their customer interactions and relationships effectively. The Twenty API provides programmatic access to the features and functionalities of the Twenty CRM platform, allowing developers to integrate and interact with the CRM data and operations.

    The version of the OpenAPI document: v0.1
    Contact: felix@twenty.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from uuid import UUID
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class WorkflowVersionForResponse(BaseModel):
    """
    A workflow version
    """ # noqa: E501
    id: Optional[UUID] = Field(default=None, description="Id")
    created_at: Optional[datetime] = Field(default=None, description="Creation date", alias="createdAt")
    updated_at: Optional[datetime] = Field(default=None, description="Last time the record was changed", alias="updatedAt")
    deleted_at: Optional[datetime] = Field(default=None, description="Date when the record was deleted", alias="deletedAt")
    name: Optional[StrictStr] = Field(default=None, description="The workflow version name")
    trigger: Optional[Dict[str, Any]] = Field(default=None, description="Json object to provide trigger")
    steps: Optional[Dict[str, Any]] = Field(default=None, description="Json object to provide steps")
    status: Optional[StrictStr] = Field(default=None, description="The workflow version status")
    position: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Workflow version position")
    workflow_id: Optional[UUID] = Field(default=None, alias="workflowId")
    favorites: Optional[List[FavoriteForResponse]] = Field(default=None, description="Favorites linked to the workflow version")
    timeline_activities: Optional[List[TimelineActivityForResponse]] = Field(default=None, description="Timeline activities linked to the version", alias="timelineActivities")
    workflow: Optional[WorkflowForResponse] = None
    runs: Optional[List[WorkflowRunForResponse]] = Field(default=None, description="Workflow runs linked to the version.")
    __properties: ClassVar[List[str]] = ["id", "createdAt", "updatedAt", "deletedAt", "name", "trigger", "steps", "status", "position", "workflowId", "favorites", "timelineActivities", "workflow", "runs"]

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['DRAFT', 'ACTIVE', 'DEACTIVATED', 'ARCHIVED']):
            raise ValueError("must be one of enum values ('DRAFT', 'ACTIVE', 'DEACTIVATED', 'ARCHIVED')")
        return value

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of WorkflowVersionForResponse 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 each item in favorites (list)
        _items = []
        if self.favorites:
            for _item_favorites in self.favorites:
                if _item_favorites:
                    _items.append(_item_favorites.to_dict())
            _dict['favorites'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in timeline_activities (list)
        _items = []
        if self.timeline_activities:
            for _item_timeline_activities in self.timeline_activities:
                if _item_timeline_activities:
                    _items.append(_item_timeline_activities.to_dict())
            _dict['timelineActivities'] = _items
        # override the default output from pydantic by calling `to_dict()` of workflow
        if self.workflow:
            _dict['workflow'] = self.workflow.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in runs (list)
        _items = []
        if self.runs:
            for _item_runs in self.runs:
                if _item_runs:
                    _items.append(_item_runs.to_dict())
            _dict['runs'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt"),
            "deletedAt": obj.get("deletedAt"),
            "name": obj.get("name"),
            "trigger": obj.get("trigger"),
            "steps": obj.get("steps"),
            "status": obj.get("status"),
            "position": obj.get("position"),
            "workflowId": obj.get("workflowId"),
            "favorites": [FavoriteForResponse.from_dict(_item) for _item in obj["favorites"]] if obj.get("favorites") is not None else None,
            "timelineActivities": [TimelineActivityForResponse.from_dict(_item) for _item in obj["timelineActivities"]] if obj.get("timelineActivities") is not None else None,
            "workflow": WorkflowForResponse.from_dict(obj["workflow"]) if obj.get("workflow") is not None else None,
            "runs": [WorkflowRunForResponse.from_dict(_item) for _item in obj["runs"]] if obj.get("runs") is not None else None
        })
        return _obj

from twentycrm_client.models.favorite_for_response import FavoriteForResponse
from twentycrm_client.models.timeline_activity_for_response import TimelineActivityForResponse
from twentycrm_client.models.workflow_for_response import WorkflowForResponse
from twentycrm_client.models.workflow_run_for_response import WorkflowRunForResponse
# TODO: Rewrite to not use raise_errors
WorkflowVersionForResponse.model_rebuild(raise_errors=False)

