# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.custom_payload_field import CustomPayloadField
from instana_client.models.service_levels_alert_rule import ServiceLevelsAlertRule
from instana_client.models.service_levels_burn_rate_config import ServiceLevelsBurnRateConfig
from instana_client.models.service_levels_burn_rate_time_windows import ServiceLevelsBurnRateTimeWindows
from instana_client.models.service_levels_time_threshold import ServiceLevelsTimeThreshold
from instana_client.models.static_threshold import StaticThreshold
from typing import Optional, Set
from typing_extensions import Self

class ServiceLevelsAlertConfig(BaseModel):
    """
    ServiceLevelsAlertConfig
    """ # noqa: E501
    alert_channel_ids: Annotated[List[StrictStr], Field(min_length=0, max_length=1024)] = Field(description="This is the list of channel IDs when alert triggered and sent to.", alias="alertChannelIds")
    burn_rate_config: Optional[List[ServiceLevelsBurnRateConfig]] = Field(default=None, description="This is the burn rate alert configuration which defines alerting windows and corresponding thresholds. This configuration must to specified for BURN_RATE_V2 Alerts.", alias="burnRateConfig")
    burn_rate_time_windows: Optional[ServiceLevelsBurnRateTimeWindows] = Field(default=None, alias="burnRateTimeWindows")
    custom_payload_fields: Annotated[List[CustomPayloadField], Field(min_length=0, max_length=20)] = Field(description="This is the custom name and value pairs to be sent along with the alert to the alert channels.", alias="customPayloadFields")
    description: Annotated[str, Field(min_length=0, strict=True, max_length=65536)] = Field(description="The description of the alert. It is also the alert message content.")
    name: Annotated[str, Field(min_length=0, strict=True, max_length=256)] = Field(description="Name of the Service Levels Smart Alerts Configuration.")
    rule: ServiceLevelsAlertRule
    severity: StrictInt = Field(description="This is the severity of the alert. The value can be: <b>5</b>: warning, <b>10</b>: critical.")
    slo_ids: Annotated[List[StrictStr], Field(min_length=0, max_length=1024)] = Field(description="This is the list of SLO configurations related to this alert.", alias="sloIds")
    threshold: Optional[StaticThreshold] = None
    time_threshold: ServiceLevelsTimeThreshold = Field(alias="timeThreshold")
    triggering: Optional[StrictBool] = Field(default=None, description="Incident flag. If value is true, this alert will become an accident.")
    __properties: ClassVar[List[str]] = ["alertChannelIds", "burnRateConfig", "burnRateTimeWindows", "customPayloadFields", "description", "name", "rule", "severity", "sloIds", "threshold", "timeThreshold", "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 ServiceLevelsAlertConfig 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 burn_rate_config (list)
        _items = []
        if self.burn_rate_config:
            for _item_burn_rate_config in self.burn_rate_config:
                if _item_burn_rate_config:
                    _items.append(_item_burn_rate_config.to_dict())
            _dict['burnRateConfig'] = _items
        # override the default output from pydantic by calling `to_dict()` of burn_rate_time_windows
        if self.burn_rate_time_windows:
            _dict['burnRateTimeWindows'] = self.burn_rate_time_windows.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in custom_payload_fields (list)
        _items = []
        if self.custom_payload_fields:
            for _item_custom_payload_fields in self.custom_payload_fields:
                if _item_custom_payload_fields:
                    _items.append(_item_custom_payload_fields.to_dict())
            _dict['customPayloadFields'] = _items
        # override the default output from pydantic by calling `to_dict()` of rule
        if self.rule:
            _dict['rule'] = self.rule.to_dict()
        # override the default output from pydantic by calling `to_dict()` of threshold
        if self.threshold:
            _dict['threshold'] = self.threshold.to_dict()
        # override the default output from pydantic by calling `to_dict()` of time_threshold
        if self.time_threshold:
            _dict['timeThreshold'] = self.time_threshold.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "alertChannelIds": obj.get("alertChannelIds"),
            "burnRateConfig": [ServiceLevelsBurnRateConfig.from_dict(_item) for _item in obj["burnRateConfig"]] if obj.get("burnRateConfig") is not None else None,
            "burnRateTimeWindows": ServiceLevelsBurnRateTimeWindows.from_dict(obj["burnRateTimeWindows"]) if obj.get("burnRateTimeWindows") is not None else None,
            "customPayloadFields": [CustomPayloadField.from_dict(_item) for _item in obj["customPayloadFields"]] if obj.get("customPayloadFields") is not None else None,
            "description": obj.get("description"),
            "name": obj.get("name"),
            "rule": ServiceLevelsAlertRule.from_dict(obj["rule"]) if obj.get("rule") is not None else None,
            "severity": obj.get("severity"),
            "sloIds": obj.get("sloIds"),
            "threshold": StaticThreshold.from_dict(obj["threshold"]) if obj.get("threshold") is not None else None,
            "timeThreshold": ServiceLevelsTimeThreshold.from_dict(obj["timeThreshold"]) if obj.get("timeThreshold") is not None else None,
            "triggering": obj.get("triggering")
        })
        return _obj


