# coding: utf-8

"""
    FlowHunt

    FlowHunt API

    The version of the OpenAPI document: 2.0.0
    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 flowhunt.models.flow_config import FlowConfig
from flowhunt.models.flow_type import FlowType
from typing import Optional, Set
from typing_extensions import Self

class FlowDetailResponse(BaseModel):
    """
    FlowDetailResponse
    """ # noqa: E501
    id: StrictStr = Field(description="Flow ID")
    name: StrictStr = Field(description="Flow name")
    description: StrictStr = Field(description="Flow description")
    detailed_description: Optional[StrictStr] = None
    config: FlowConfig = Field(description="Flow configuration")
    flow_type: FlowType = Field(description="Flow type")
    executed_at: Optional[datetime] = None
    category_id: Optional[StrictStr] = None
    branch: StrictStr = Field(description="Flow branch")
    enable_cache: StrictBool = Field(description="Enable cache")
    draft_version_nr: Optional[StrictInt] = None
    prod_version_nr: Optional[StrictInt] = None
    last_modified: Optional[datetime] = None
    __properties: ClassVar[List[str]] = ["id", "name", "description", "detailed_description", "config", "flow_type", "executed_at", "category_id", "branch", "enable_cache", "draft_version_nr", "prod_version_nr", "last_modified"]

    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 FlowDetailResponse 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 config
        if self.config:
            _dict['config'] = self.config.to_dict()
        # set to None if detailed_description (nullable) is None
        # and model_fields_set contains the field
        if self.detailed_description is None and "detailed_description" in self.model_fields_set:
            _dict['detailed_description'] = None

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of FlowDetailResponse 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"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "detailed_description": obj.get("detailed_description"),
            "config": FlowConfig.from_dict(obj["config"]) if obj.get("config") is not None else None,
            "flow_type": obj.get("flow_type"),
            "executed_at": obj.get("executed_at"),
            "category_id": obj.get("category_id"),
            "branch": obj.get("branch"),
            "enable_cache": obj.get("enable_cache"),
            "draft_version_nr": obj.get("draft_version_nr"),
            "prod_version_nr": obj.get("prod_version_nr"),
            "last_modified": obj.get("last_modified")
        })
        return _obj


