# 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 twentycrm_client.models.attachment_for_response import AttachmentForResponse
from twentycrm_client.models.attachment_for_response_created_by import AttachmentForResponseCreatedBy
from twentycrm_client.models.attachment_for_response_updated_by import AttachmentForResponseUpdatedBy
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class WorkflowForResponse(BaseModel):
    """
    A workflow
    """ # 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 name")
    last_published_version_id: Optional[StrictStr] = Field(default=None, description="The workflow last published version id", alias="lastPublishedVersionId")
    statuses: Optional[List[StrictStr]] = Field(default=None, description="The current statuses of the workflow versions")
    position: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Workflow record position")
    created_by: Optional[AttachmentForResponseCreatedBy] = Field(default=None, alias="createdBy")
    updated_by: Optional[AttachmentForResponseUpdatedBy] = Field(default=None, alias="updatedBy")
    attachments: Optional[List[AttachmentForResponse]] = Field(default=None, description="Attachments linked to the workflow")
    favorites: Optional[List[FavoriteForResponse]] = Field(default=None, description="Favorites linked to the workflow")
    timeline_activities: Optional[List[TimelineActivityForResponse]] = Field(default=None, description="Timeline activities linked to the workflow", alias="timelineActivities")
    versions: Optional[List[WorkflowVersionForResponse]] = Field(default=None, description="Workflow versions linked to the workflow.")
    runs: Optional[List[WorkflowRunForResponse]] = Field(default=None, description="Workflow runs linked to the workflow.")
    automated_triggers: Optional[List[WorkflowAutomatedTriggerForResponse]] = Field(default=None, description="Workflow automated triggers linked to the workflow.", alias="automatedTriggers")
    __properties: ClassVar[List[str]] = ["id", "createdAt", "updatedAt", "deletedAt", "name", "lastPublishedVersionId", "statuses", "position", "createdBy", "updatedBy", "attachments", "favorites", "timelineActivities", "versions", "runs", "automatedTriggers"]

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

        for i in value:
            if i not in set(['DRAFT', 'ACTIVE', 'DEACTIVATED']):
                raise ValueError("each list item must be one of ('DRAFT', 'ACTIVE', 'DEACTIVATED')")
        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 WorkflowForResponse 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 created_by
        if self.created_by:
            _dict['createdBy'] = self.created_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of updated_by
        if self.updated_by:
            _dict['updatedBy'] = self.updated_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in attachments (list)
        _items = []
        if self.attachments:
            for _item_attachments in self.attachments:
                if _item_attachments:
                    _items.append(_item_attachments.to_dict())
            _dict['attachments'] = _items
        # 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 each item in versions (list)
        _items = []
        if self.versions:
            for _item_versions in self.versions:
                if _item_versions:
                    _items.append(_item_versions.to_dict())
            _dict['versions'] = _items
        # 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
        # override the default output from pydantic by calling `to_dict()` of each item in automated_triggers (list)
        _items = []
        if self.automated_triggers:
            for _item_automated_triggers in self.automated_triggers:
                if _item_automated_triggers:
                    _items.append(_item_automated_triggers.to_dict())
            _dict['automatedTriggers'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of WorkflowForResponse 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"),
            "lastPublishedVersionId": obj.get("lastPublishedVersionId"),
            "statuses": obj.get("statuses"),
            "position": obj.get("position"),
            "createdBy": AttachmentForResponseCreatedBy.from_dict(obj["createdBy"]) if obj.get("createdBy") is not None else None,
            "updatedBy": AttachmentForResponseUpdatedBy.from_dict(obj["updatedBy"]) if obj.get("updatedBy") is not None else None,
            "attachments": [AttachmentForResponse.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "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,
            "versions": [WorkflowVersionForResponse.from_dict(_item) for _item in obj["versions"]] if obj.get("versions") is not None else None,
            "runs": [WorkflowRunForResponse.from_dict(_item) for _item in obj["runs"]] if obj.get("runs") is not None else None,
            "automatedTriggers": [WorkflowAutomatedTriggerForResponse.from_dict(_item) for _item in obj["automatedTriggers"]] if obj.get("automatedTriggers") 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_automated_trigger_for_response import WorkflowAutomatedTriggerForResponse
from twentycrm_client.models.workflow_run_for_response import WorkflowRunForResponse
from twentycrm_client.models.workflow_version_for_response import WorkflowVersionForResponse
# TODO: Rewrite to not use raise_errors
WorkflowForResponse.model_rebuild(raise_errors=False)

