# 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.6.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, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from wrk_platform_sdk.models.wrk_action_resource_reference import WrkActionResourceReference
from wrk_platform_sdk.models.wrk_action_spec_cost import WrkActionSpecCost
from typing import Optional, Set
from typing_extensions import Self

class WrkActionSpec(BaseModel):
    """
    WrkActionSpec
    """ # noqa: E501
    application_ref: Optional[WrkActionResourceReference] = Field(default=None, alias="applicationRef")
    category_ref: WrkActionResourceReference = Field(alias="categoryRef")
    config_values: Dict[str, Any] = Field(alias="configValues")
    cost: Optional[WrkActionSpecCost] = None
    credential_refs: Optional[List[WrkActionResourceReference]] = Field(default=None, alias="credentialRefs")
    delivery_method_refs: List[WrkActionResourceReference] = Field(alias="deliveryMethodRefs")
    disallow_self_additional_input: StrictBool = Field(alias="disallowSelfAdditionalInput")
    disallow_self_additional_output: StrictBool = Field(alias="disallowSelfAdditionalOutput")
    display_name: StrictStr = Field(alias="displayName")
    documentation_link_url: Optional[StrictStr] = Field(default=None, alias="documentationLinkUrl")
    input_schema: Dict[str, Any] = Field(alias="inputSchema")
    oauth_scope_refs: List[WrkActionResourceReference] = Field(alias="oauthScopeRefs")
    outcome_refs: List[WrkActionResourceReference] = Field(alias="outcomeRefs")
    output_schema: Dict[str, Any] = Field(alias="outputSchema")
    summary: StrictStr
    tag_refs: List[WrkActionResourceReference] = Field(alias="tagRefs")
    visibility: StrictStr
    __properties: ClassVar[List[str]] = ["applicationRef", "categoryRef", "configValues", "cost", "credentialRefs", "deliveryMethodRefs", "disallowSelfAdditionalInput", "disallowSelfAdditionalOutput", "displayName", "documentationLinkUrl", "inputSchema", "oauthScopeRefs", "outcomeRefs", "outputSchema", "summary", "tagRefs", "visibility"]

    @field_validator('visibility')
    def visibility_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['VISIBLE', 'HIDDEN', 'RETIRED']):
            raise ValueError("must be one of enum values ('VISIBLE', 'HIDDEN', 'RETIRED')")
        return value

    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 WrkActionSpec 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 application_ref
        if self.application_ref:
            _dict['applicationRef'] = self.application_ref.to_dict()
        # override the default output from pydantic by calling `to_dict()` of category_ref
        if self.category_ref:
            _dict['categoryRef'] = self.category_ref.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cost
        if self.cost:
            _dict['cost'] = self.cost.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in credential_refs (list)
        _items = []
        if self.credential_refs:
            for _item_credential_refs in self.credential_refs:
                if _item_credential_refs:
                    _items.append(_item_credential_refs.to_dict())
            _dict['credentialRefs'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in delivery_method_refs (list)
        _items = []
        if self.delivery_method_refs:
            for _item_delivery_method_refs in self.delivery_method_refs:
                if _item_delivery_method_refs:
                    _items.append(_item_delivery_method_refs.to_dict())
            _dict['deliveryMethodRefs'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in oauth_scope_refs (list)
        _items = []
        if self.oauth_scope_refs:
            for _item_oauth_scope_refs in self.oauth_scope_refs:
                if _item_oauth_scope_refs:
                    _items.append(_item_oauth_scope_refs.to_dict())
            _dict['oauthScopeRefs'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in outcome_refs (list)
        _items = []
        if self.outcome_refs:
            for _item_outcome_refs in self.outcome_refs:
                if _item_outcome_refs:
                    _items.append(_item_outcome_refs.to_dict())
            _dict['outcomeRefs'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in tag_refs (list)
        _items = []
        if self.tag_refs:
            for _item_tag_refs in self.tag_refs:
                if _item_tag_refs:
                    _items.append(_item_tag_refs.to_dict())
            _dict['tagRefs'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "applicationRef": WrkActionResourceReference.from_dict(obj["applicationRef"]) if obj.get("applicationRef") is not None else None,
            "categoryRef": WrkActionResourceReference.from_dict(obj["categoryRef"]) if obj.get("categoryRef") is not None else None,
            "configValues": obj.get("configValues"),
            "cost": WrkActionSpecCost.from_dict(obj["cost"]) if obj.get("cost") is not None else None,
            "credentialRefs": [WrkActionResourceReference.from_dict(_item) for _item in obj["credentialRefs"]] if obj.get("credentialRefs") is not None else None,
            "deliveryMethodRefs": [WrkActionResourceReference.from_dict(_item) for _item in obj["deliveryMethodRefs"]] if obj.get("deliveryMethodRefs") is not None else None,
            "disallowSelfAdditionalInput": obj.get("disallowSelfAdditionalInput"),
            "disallowSelfAdditionalOutput": obj.get("disallowSelfAdditionalOutput"),
            "displayName": obj.get("displayName"),
            "documentationLinkUrl": obj.get("documentationLinkUrl"),
            "inputSchema": obj.get("inputSchema"),
            "oauthScopeRefs": [WrkActionResourceReference.from_dict(_item) for _item in obj["oauthScopeRefs"]] if obj.get("oauthScopeRefs") is not None else None,
            "outcomeRefs": [WrkActionResourceReference.from_dict(_item) for _item in obj["outcomeRefs"]] if obj.get("outcomeRefs") is not None else None,
            "outputSchema": obj.get("outputSchema"),
            "summary": obj.get("summary"),
            "tagRefs": [WrkActionResourceReference.from_dict(_item) for _item in obj["tagRefs"]] if obj.get("tagRefs") is not None else None,
            "visibility": obj.get("visibility")
        })
        return _obj


