# coding: utf-8

"""
    Instana REST API documentation

    Documentation for INSTANA REST API

    The version of the OpenAPI document: 1.309.1268
    Contact: support@instana.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 instana_client.models.action_instance_request_parameters import ActionInstanceRequestParameters
from typing import Optional, Set
from typing_extensions import Self

class ActionInstanceRequest(BaseModel):
    """
    ActionInstanceRequest
    """ # noqa: E501
    action_id: StrictStr = Field(description="Action identifier of the action to run.", alias="actionId")
    var_async: Optional[StrictStr] = Field(default=None, description="`\"true\"` if the action should be run in asynchronous mode `\"false\"` otherwise. Default is `\"true\"`.", alias="async")
    event_id: Optional[StrictStr] = Field(default=None, description="Event identifier (incident or issue) associated with the policy.", alias="eventId")
    host_id: StrictStr = Field(description="Agent host identifier on which to run the action.", alias="hostId")
    input_parameters: Optional[List[ActionInstanceRequestParameters]] = Field(default=None, description="Action run input parameters.", alias="inputParameters")
    policy_id: Optional[StrictStr] = Field(default=None, description="Policy identifier that associates the action trigger (incident or issue) to the action to run.", alias="policyId")
    timeout: Optional[StrictStr] = Field(default=None, description="Action run time out. Default is `30 seconds`.")
    __properties: ClassVar[List[str]] = ["actionId", "async", "eventId", "hostId", "inputParameters", "policyId", "timeout"]

    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 ActionInstanceRequest 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 input_parameters (list)
        _items = []
        if self.input_parameters:
            for _item_input_parameters in self.input_parameters:
                if _item_input_parameters:
                    _items.append(_item_input_parameters.to_dict())
            _dict['inputParameters'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "actionId": obj.get("actionId"),
            "async": obj.get("async"),
            "eventId": obj.get("eventId"),
            "hostId": obj.get("hostId"),
            "inputParameters": [ActionInstanceRequestParameters.from_dict(_item) for _item in obj["inputParameters"]] if obj.get("inputParameters") is not None else None,
            "policyId": obj.get("policyId"),
            "timeout": obj.get("timeout")
        })
        return _obj


