# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from instana_client.models.tag_filter_expression_element import TagFilterExpressionElement
from typing import Optional, Set
from typing_extensions import Self

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from instana_client.models.application_apdex_entity import ApplicationApdexEntity
    from instana_client.models.website_apdex_entity import WebsiteApdexEntity

class ApdexEntity(BaseModel):
    """
    Entity which holds the information of Apdex Configuration
    """ # noqa: E501
    apdex_type: StrictStr = Field(alias="apdexType")
    entity_id: StrictStr = Field(alias="entityId")
    tag_filter_expression: TagFilterExpressionElement = Field(alias="tagFilterExpression")
    threshold: Optional[Annotated[int, Field(strict=True, ge=1)]] = None
    __properties: ClassVar[List[str]] = ["apdexType", "entityId", "tagFilterExpression", "threshold"]

    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] = 'apdexType'

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        'application': 'ApplicationApdexEntity','website': 'WebsiteApdexEntity'
    }

    @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[ApplicationApdexEntity, WebsiteApdexEntity]]:
        """Create an instance of ApdexEntity 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 tag_filter_expression
        if self.tag_filter_expression:
            _dict['tagFilterExpression'] = self.tag_filter_expression.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[ApplicationApdexEntity, WebsiteApdexEntity]]:
        """Create an instance of ApdexEntity from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type ==  'ApplicationApdexEntity':
            return import_module("instana_client.models.application_apdex_entity").ApplicationApdexEntity.from_dict(obj)
        if object_type ==  'WebsiteApdexEntity':
            return import_module("instana_client.models.website_apdex_entity").WebsiteApdexEntity.from_dict(obj)

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


