# coding: utf-8

"""
    Wrk Automation Platform - API v1

    The Wrk API is organized around REST. Our API has predictable resource-oriented URLs, accepts and returns JSON-encoded requests and responses. It uses standard HTTP response codes, authentication, and verbs.  Please note you need will an API key with the appropriate access to use the following APIs. The API key can be obtained from [this page](https://account.wrk.com/api-key) in your Wrk account. To elevate access to your account, please [contact your Sales team](https://www.wrk.com/meet-automation-expert).

    The version of the OpenAPI document: 2.4.0
    Contact: support@wrk.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 pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from wrk_platform_sdk.models.wrkflow_definition import WrkflowDefinition
from wrk_platform_sdk.models.wrkflow_schedule import WrkflowSchedule
from typing import Optional, Set
from typing_extensions import Self

class Wrkflow(BaseModel):
    """
    This object represents an automation workflow (Wrkflow) in your account. Use it to get Launch parameters and launch it. You can use the Launch object to track the progress.
    """ # noqa: E501
    uuid: StrictStr = Field(description="The unique identifier of the Wrkflow")
    name: StrictStr = Field(description="The name of the Wrkflow")
    short_description: Optional[StrictStr] = Field(default=None, description="A short description of the Wrkflow")
    long_description: Optional[StrictStr] = Field(default=None, description="A long description of the Wrkflow. Usually used to provide instructions on how to use the Wrfklow.")
    launch_parameters_json_schema: Optional[Dict[str, Any]] = Field(default=None, description="A JSON object with properties containing the launch parameters required to launch the Wrkflow. The property required contains the minimum required properties to launch the Wrkflow.")
    webhook_url: Optional[StrictStr] = Field(default=None, description="A URL to launch the Wrkflow via webhook")
    schedules: Optional[List[WrkflowSchedule]] = None
    wrkflow_definition: Optional[WrkflowDefinition] = None
    __properties: ClassVar[List[str]] = ["uuid", "name", "short_description", "long_description", "launch_parameters_json_schema", "webhook_url", "schedules", "wrkflow_definition"]

    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 Wrkflow 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 schedules (list)
        _items = []
        if self.schedules:
            for _item_schedules in self.schedules:
                if _item_schedules:
                    _items.append(_item_schedules.to_dict())
            _dict['schedules'] = _items
        # override the default output from pydantic by calling `to_dict()` of wrkflow_definition
        if self.wrkflow_definition:
            _dict['wrkflow_definition'] = self.wrkflow_definition.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "uuid": obj.get("uuid"),
            "name": obj.get("name"),
            "short_description": obj.get("short_description"),
            "long_description": obj.get("long_description"),
            "launch_parameters_json_schema": obj.get("launch_parameters_json_schema"),
            "webhook_url": obj.get("webhook_url"),
            "schedules": [WrkflowSchedule.from_dict(_item) for _item in obj["schedules"]] if obj.get("schedules") is not None else None,
            "wrkflow_definition": WrkflowDefinition.from_dict(obj["wrkflow_definition"]) if obj.get("wrkflow_definition") is not None else None
        })
        return _obj


