# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.problem import Problem
from typing import Optional, Set
from typing_extensions import Self

class Event(BaseModel):
    """
    Event
    """ # noqa: E501
    affected_entities: Optional[List[StrictStr]] = Field(default=None, alias="affectedEntities")
    end: Optional[Annotated[int, Field(strict=True, ge=1)]] = None
    endpoint_service_id: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=64)]] = Field(default=None, alias="endpointServiceId")
    entity_id: Annotated[str, Field(min_length=0, strict=True, max_length=64)] = Field(alias="entityId")
    entity_type: Optional[StrictStr] = Field(default=None, alias="entityType")
    event_configuration_type: Optional[StrictStr] = Field(default=None, alias="eventConfigurationType")
    id: Annotated[str, Field(min_length=0, strict=True, max_length=64)]
    long_form_plugin_id: Optional[StrictStr] = Field(default=None, alias="longFormPluginId")
    metadata: Optional[Dict[str, Dict[str, Any]]] = None
    metric_access_id: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=64)]] = Field(default=None, alias="metricAccessId")
    plugin: Annotated[str, Field(min_length=0, strict=True, max_length=256)]
    problem: Optional[Problem] = None
    rca: Optional[Dict[str, Dict[str, Any]]] = None
    short_code: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=64)]] = Field(default=None, alias="shortCode")
    start: Optional[Annotated[int, Field(strict=True, ge=1)]] = None
    state: Annotated[str, Field(min_length=0, strict=True, max_length=8)]
    type: Annotated[str, Field(min_length=0, strict=True, max_length=64)]
    __properties: ClassVar[List[str]] = ["affectedEntities", "end", "endpointServiceId", "entityId", "entityType", "eventConfigurationType", "id", "longFormPluginId", "metadata", "metricAccessId", "plugin", "problem", "rca", "shortCode", "start", "state", "type"]

    @field_validator('entity_type')
    def entity_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['Entity10', 'App20', 'Service20', 'Endpoint20', 'Website', 'Synthetic', 'MobileApp', 'Log']):
            raise ValueError("must be one of enum values ('Entity10', 'App20', 'Service20', 'Endpoint20', 'Website', 'Synthetic', 'MobileApp', 'Log')")
        return value

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

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

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

        _obj = cls.model_validate({
            "affectedEntities": obj.get("affectedEntities"),
            "end": obj.get("end"),
            "endpointServiceId": obj.get("endpointServiceId"),
            "entityId": obj.get("entityId"),
            "entityType": obj.get("entityType"),
            "eventConfigurationType": obj.get("eventConfigurationType"),
            "id": obj.get("id"),
            "longFormPluginId": obj.get("longFormPluginId"),
            "metadata": obj.get("metadata"),
            "metricAccessId": obj.get("metricAccessId"),
            "plugin": obj.get("plugin"),
            "problem": Problem.from_dict(obj["problem"]) if obj.get("problem") is not None else None,
            "rca": obj.get("rca"),
            "shortCode": obj.get("shortCode"),
            "start": obj.get("start"),
            "state": obj.get("state"),
            "type": obj.get("type")
        })
        return _obj


