# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 4.202.1-ai-plus
    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from uuid import UUID
from typing import Optional, Set
from typing_extensions import Self

class PatchedWorkflow(BaseModel):
    """
    Serializer for Workflow CRUD operations.  Provides basic ReactFlow JSON validation (Phase 1) to ensure definitions are renderable, while allowing draft workflows that may not be executable.  Comprehensive execution validation (Phase 2) is available via the validate action endpoint.  Fields: - All model fields are exposed - Platform and creator are set automatically from URL context - Read-only fields: id, unique_id, created_at, updated_at - Chat settings (chat_name, chat_greeting, etc.) update the entry_mentor
    """ # noqa: E501
    id: Optional[StrictInt] = None
    unique_id: Optional[UUID] = None
    name: Optional[Annotated[str, Field(strict=True, max_length=255)]] = None
    description: Optional[StrictStr] = None
    definition: Optional[Any] = Field(default=None, description="Workflow definition in ReactFlow format")
    is_active: Optional[StrictBool] = None
    is_template: Optional[StrictBool] = None
    parent_workflow: Optional[StrictInt] = Field(default=None, description="Parent workflow if this is a template variant")
    platform: Optional[StrictInt] = None
    platform_key: Optional[StrictStr] = None
    platform_name: Optional[StrictStr] = None
    created_by: Optional[StrictInt] = Field(default=None, description="edX user ID")
    created_by_username: Optional[StrictStr] = None
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
    node_count: Optional[StrictInt] = Field(default=None, description="Get the number of nodes in the workflow definition.")
    edge_count: Optional[StrictInt] = Field(default=None, description="Get the number of edges in the workflow definition.")
    entry_mentor_id: Optional[UUID] = None
    chat_name: Optional[StrictStr] = Field(default=None, description="Display name for chat (updates entry_mentor.name)")
    chat_proactive_response: Optional[StrictStr] = Field(default=None, description="Proactive greeting message for chat (updates entry_mentor.proactive_response)")
    __properties: ClassVar[List[str]] = ["id", "unique_id", "name", "description", "definition", "is_active", "is_template", "parent_workflow", "platform", "platform_key", "platform_name", "created_by", "created_by_username", "created_at", "updated_at", "node_count", "edge_count", "entry_mentor_id", "chat_name", "chat_proactive_response"]

    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 PatchedWorkflow 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "unique_id",
            "platform",
            "platform_key",
            "platform_name",
            "created_by",
            "created_by_username",
            "created_at",
            "updated_at",
            "node_count",
            "edge_count",
            "entry_mentor_id",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if definition (nullable) is None
        # and model_fields_set contains the field
        if self.definition is None and "definition" in self.model_fields_set:
            _dict['definition'] = None

        # set to None if parent_workflow (nullable) is None
        # and model_fields_set contains the field
        if self.parent_workflow is None and "parent_workflow" in self.model_fields_set:
            _dict['parent_workflow'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of PatchedWorkflow 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"),
            "unique_id": obj.get("unique_id"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "definition": obj.get("definition"),
            "is_active": obj.get("is_active"),
            "is_template": obj.get("is_template"),
            "parent_workflow": obj.get("parent_workflow"),
            "platform": obj.get("platform"),
            "platform_key": obj.get("platform_key"),
            "platform_name": obj.get("platform_name"),
            "created_by": obj.get("created_by"),
            "created_by_username": obj.get("created_by_username"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "node_count": obj.get("node_count"),
            "edge_count": obj.get("edge_count"),
            "entry_mentor_id": obj.get("entry_mentor_id"),
            "chat_name": obj.get("chat_name"),
            "chat_proactive_response": obj.get("chat_proactive_response")
        })
        return _obj


