# 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 importlib import import_module
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from instana_client.models.application_event_result import ApplicationEventResult
    from instana_client.models.endpoint_event_result import EndpointEventResult
    from instana_client.models.infra_event_result import InfraEventResult
    from instana_client.models.log_event_result import LogEventResult
    from instana_client.models.mobile_app_event_result import MobileAppEventResult
    from instana_client.models.service_event_result import ServiceEventResult
    from instana_client.models.synthetics_event_result import SyntheticsEventResult
    from instana_client.models.website_event_result import WebsiteEventResult

class EventResult(BaseModel):
    """
    EventResult
    """ # noqa: E501
    detail: Optional[StrictStr] = Field(default=None, description="Details of the event.")
    end: Optional[StrictInt] = Field(default=None, description="A Unix timestamp representing the end time of the Event.")
    entity_label: Optional[StrictStr] = Field(default=None, description="The label of the affected entity of the event.", alias="entityLabel")
    entity_name: Optional[StrictStr] = Field(default=None, description="The name or type of the affected entity of the event.", alias="entityName")
    entity_type: Optional[StrictStr] = Field(default=None, description="The category of the affected entity.", alias="entityType")
    event_id: Optional[StrictStr] = Field(default=None, description="ID of this Event.", alias="eventId")
    event_specification_id: Optional[StrictStr] = Field(default=None, description="ID of the configuration that created this event.", alias="eventSpecificationId")
    fix_suggestion: Optional[StrictStr] = Field(default=None, description="Details of the event.", alias="fixSuggestion")
    metrics: Optional[List[Dict[str, Dict[str, Any]]]] = Field(default=None, description="List of metrics associated with the Event.")
    probable_cause: Optional[Dict[str, Dict[str, Any]]] = Field(default=None, description="Metadata of the probable root cause for this event. Only present in case of specific \"Incident\" type events.", alias="probableCause")
    problem: Optional[StrictStr] = Field(default=None, description="Main problem title of the Event.")
    recent_events: Optional[List[Dict[str, Dict[str, Any]]]] = Field(default=None, description="List of related recent events. Only present in case of \"Incident\" type events.", alias="recentEvents")
    severity: Optional[StrictInt] = Field(default=None, description="The severity of the Event when triggered.")
    short_code: Optional[StrictStr] = Field(default=None, description="A short code for the event", alias="shortCode")
    snapshot_id: Optional[StrictStr] = Field(default=None, description="The snapshot ID of the affected entity of this event.", alias="snapshotId")
    start: Optional[StrictInt] = Field(default=None, description="A Unix timestamp representing the start time of the Event.")
    state: Optional[StrictStr] = Field(default=None, description="The state of the Event, \"open\" or \"close\". ")
    type: Optional[StrictStr] = Field(default=None, description="The type of Event.")
    __properties: ClassVar[List[str]] = ["detail", "end", "entityLabel", "entityName", "entityType", "eventId", "eventSpecificationId", "fixSuggestion", "metrics", "probableCause", "problem", "recentEvents", "severity", "shortCode", "snapshotId", "start", "state", "type"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    # JSON field name that stores the object type
    __discriminator_property_name: ClassVar[str] = 'entityType'

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        'APPLICATION': 'ApplicationEventResult','ENDPOINT': 'EndpointEventResult','INFRASTRUCTURE': 'InfraEventResult','LOG': 'LogEventResult','MOBILE_APP': 'MobileAppEventResult','SERVICE': 'ServiceEventResult','SYNTHETICS': 'SyntheticsEventResult','WEBSITE': 'WebsiteEventResult'
    }

    @classmethod
    def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
        """Returns the discriminator value (object type) of the data"""
        discriminator_value = obj[cls.__discriminator_property_name]
        if discriminator_value:
            return cls.__discriminator_value_class_map.get(discriminator_value)
        else:
            return None

    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[Union[ApplicationEventResult, EndpointEventResult, InfraEventResult, LogEventResult, MobileAppEventResult, ServiceEventResult, SyntheticsEventResult, WebsiteEventResult]]:
        """Create an instance of EventResult 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,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[ApplicationEventResult, EndpointEventResult, InfraEventResult, LogEventResult, MobileAppEventResult, ServiceEventResult, SyntheticsEventResult, WebsiteEventResult]]:
        """Create an instance of EventResult from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type ==  'ApplicationEventResult':
            return import_module("instana_client.models.application_event_result").ApplicationEventResult.from_dict(obj)
        if object_type ==  'EndpointEventResult':
            return import_module("instana_client.models.endpoint_event_result").EndpointEventResult.from_dict(obj)
        if object_type ==  'InfraEventResult':
            return import_module("instana_client.models.infra_event_result").InfraEventResult.from_dict(obj)
        if object_type ==  'LogEventResult':
            return import_module("instana_client.models.log_event_result").LogEventResult.from_dict(obj)
        if object_type ==  'MobileAppEventResult':
            return import_module("instana_client.models.mobile_app_event_result").MobileAppEventResult.from_dict(obj)
        if object_type ==  'ServiceEventResult':
            return import_module("instana_client.models.service_event_result").ServiceEventResult.from_dict(obj)
        if object_type ==  'SyntheticsEventResult':
            return import_module("instana_client.models.synthetics_event_result").SyntheticsEventResult.from_dict(obj)
        if object_type ==  'WebsiteEventResult':
            return import_module("instana_client.models.website_event_result").WebsiteEventResult.from_dict(obj)

        raise ValueError("EventResult failed to lookup discriminator value from " +
                            json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name +
                            ", mapping: " + json.dumps(cls.__discriminator_value_class_map))


