# 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, StrictBool, StrictInt
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.hyper_param import HyperParam
from instana_client.models.rule_input import RuleInput
from typing import Optional, Set
from typing_extensions import Self

class BuiltInEventSpecification(BaseModel):
    """
    BuiltInEventSpecification
    """ # noqa: E501
    description: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=2048)]] = Field(default=None, description="Description of Built-in Event Specification")
    enabled: Optional[StrictBool] = Field(default=None, description="Flag to show whether the Built-in Event Specification is enabled")
    hidden: Optional[StrictBool] = Field(default=None, description="Flag to show whether the Built-in Event Specification is hidden")
    hyper_params: Annotated[List[HyperParam], Field(min_length=0, max_length=32)] = Field(description="List of hyper parameters of the Built-in Event Specification", alias="hyperParams")
    id: Annotated[str, Field(min_length=0, strict=True, max_length=2048)] = Field(description="ID of Built-in Event Specification")
    name: Annotated[str, Field(min_length=0, strict=True, max_length=256)] = Field(description="Name of Built-in Event Specification")
    rule_inputs: Annotated[List[RuleInput], Field(min_length=0, max_length=32)] = Field(description="List of input rules of the Built-in Event Specification", alias="ruleInputs")
    severity: Optional[StrictInt] = Field(default=None, description="Severity level of Built-in Event Specification")
    short_plugin_id: Annotated[str, Field(min_length=0, strict=True, max_length=64)] = Field(description="ID of short plugin of Built-in Event Specification", alias="shortPluginId")
    triggering: Optional[StrictBool] = Field(default=None, description="Flag to show whether the Built-in Event Specification is triggering")
    __properties: ClassVar[List[str]] = ["description", "enabled", "hidden", "hyperParams", "id", "name", "ruleInputs", "severity", "shortPluginId", "triggering"]

    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 BuiltInEventSpecification 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 hyper_params (list)
        _items = []
        if self.hyper_params:
            for _item_hyper_params in self.hyper_params:
                if _item_hyper_params:
                    _items.append(_item_hyper_params.to_dict())
            _dict['hyperParams'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in rule_inputs (list)
        _items = []
        if self.rule_inputs:
            for _item_rule_inputs in self.rule_inputs:
                if _item_rule_inputs:
                    _items.append(_item_rule_inputs.to_dict())
            _dict['ruleInputs'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "description": obj.get("description"),
            "enabled": obj.get("enabled"),
            "hidden": obj.get("hidden"),
            "hyperParams": [HyperParam.from_dict(_item) for _item in obj["hyperParams"]] if obj.get("hyperParams") is not None else None,
            "id": obj.get("id"),
            "name": obj.get("name"),
            "ruleInputs": [RuleInput.from_dict(_item) for _item in obj["ruleInputs"]] if obj.get("ruleInputs") is not None else None,
            "severity": obj.get("severity"),
            "shortPluginId": obj.get("shortPluginId"),
            "triggering": obj.get("triggering")
        })
        return _obj


