# 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.event_filtering_configuration import EventFilteringConfiguration
from instana_client.models.static_string_field import StaticStringField
from typing import Optional, Set
from typing_extensions import Self

class AlertingConfigurationWithLastUpdated(BaseModel):
    """
    AlertingConfigurationWithLastUpdated
    """ # noqa: E501
    alert_name: Annotated[str, Field(min_length=0, strict=True, max_length=256)] = Field(description="Name of the Alert Configuration.", alias="alertName")
    custom_payload_fields: Annotated[List[StaticStringField], Field(min_length=0, max_length=20)] = Field(description="Custom payload fields to send additional information in the alert notifications. Can be left empty.", alias="customPayloadFields")
    event_filtering_configuration: EventFilteringConfiguration = Field(alias="eventFilteringConfiguration")
    id: Annotated[str, Field(min_length=0, strict=True, max_length=64)] = Field(description="ID of the Alert Configuration.")
    include_entity_name_in_legacy_alerts: Optional[StrictBool] = Field(default=None, description="To include the entity name in a legacy alert based on built-in/custom events.", alias="includeEntityNameInLegacyAlerts")
    integration_ids: Annotated[List[StrictStr], Field(min_length=0, max_length=1024)] = Field(description="List of Alert Channel IDs added in this Alert Configuration.", alias="integrationIds")
    last_updated: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=None, description="Unix timestamp representing the time the configuration was last updated.", alias="lastUpdated")
    mute_until: Optional[StrictInt] = Field(default=None, description="Timer dictating how long the Alert Configuration will stay muted. A value of `0` means the Alert Configuration is currently enabled. Otherwise, the Alert Configuration is currently disabled (muted).", alias="muteUntil")
    __properties: ClassVar[List[str]] = ["alertName", "customPayloadFields", "eventFilteringConfiguration", "id", "includeEntityNameInLegacyAlerts", "integrationIds", "lastUpdated", "muteUntil"]

    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 AlertingConfigurationWithLastUpdated 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 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 event_filtering_configuration
        if self.event_filtering_configuration:
            _dict['eventFilteringConfiguration'] = self.event_filtering_configuration.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "alertName": obj.get("alertName"),
            "customPayloadFields": [StaticStringField.from_dict(_item) for _item in obj["customPayloadFields"]] if obj.get("customPayloadFields") is not None else None,
            "eventFilteringConfiguration": EventFilteringConfiguration.from_dict(obj["eventFilteringConfiguration"]) if obj.get("eventFilteringConfiguration") is not None else None,
            "id": obj.get("id"),
            "includeEntityNameInLegacyAlerts": obj.get("includeEntityNameInLegacyAlerts"),
            "integrationIds": obj.get("integrationIds"),
            "lastUpdated": obj.get("lastUpdated"),
            "muteUntil": obj.get("muteUntil")
        })
        return _obj


