# 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 ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from instana_client.models.tag_filter_all_of_value import TagFilterAllOfValue
from instana_client.models.tag_filter_expression_element import TagFilterExpressionElement
from typing import Optional, Set
from typing_extensions import Self

class TagFilter(TagFilterExpressionElement):
    """
    TagFilter
    """ # noqa: E501
    boolean_value: Optional[StrictBool] = Field(default=None, description="Boolean value for the tag filter.", alias="booleanValue")
    entity: StrictStr = Field(description="SOURCE or DESTINATION tag in case of a call tag. For Infrastructure, always set to NOT_APPLICABLE.")
    float_value: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Float value for the tag filter.", alias="floatValue")
    key: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=512)]] = Field(default=None, description="Tag key in case of a key/value tag.")
    name: Annotated[str, Field(min_length=0, strict=True, max_length=128)] = Field(description="Name of the tag.")
    number_value: Optional[StrictInt] = Field(default=None, description="Number value for the tag filter.", alias="numberValue")
    operator: StrictStr
    string_value: Optional[StrictStr] = Field(default=None, description="String value for the tag filter.", alias="stringValue")
    value: Optional[TagFilterAllOfValue] = None
    __properties: ClassVar[List[str]] = ["type", "booleanValue", "entity", "floatValue", "key", "name", "numberValue", "operator", "stringValue", "value"]

    @field_validator('entity')
    def entity_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['NOT_APPLICABLE', 'DESTINATION', 'SOURCE']):
            raise ValueError("must be one of enum values ('NOT_APPLICABLE', 'DESTINATION', 'SOURCE')")
        return value

    @field_validator('operator')
    def operator_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['EQUALS', 'CONTAINS', 'LESS_THAN', 'LESS_OR_EQUAL_THAN', 'GREATER_THAN', 'GREATER_OR_EQUAL_THAN', 'NOT_EMPTY', 'NOT_EQUAL', 'NOT_CONTAIN', 'IS_EMPTY', 'NOT_BLANK', 'IS_BLANK', 'STARTS_WITH', 'ENDS_WITH', 'NOT_STARTS_WITH', 'NOT_ENDS_WITH', 'REGEX_MATCH']):
            raise ValueError("must be one of enum values ('EQUALS', 'CONTAINS', 'LESS_THAN', 'LESS_OR_EQUAL_THAN', 'GREATER_THAN', 'GREATER_OR_EQUAL_THAN', 'NOT_EMPTY', 'NOT_EQUAL', 'NOT_CONTAIN', 'IS_EMPTY', 'NOT_BLANK', 'IS_BLANK', 'STARTS_WITH', 'ENDS_WITH', 'NOT_STARTS_WITH', 'NOT_ENDS_WITH', 'REGEX_MATCH')")
        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 TagFilter 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 value
        if self.value:
            _dict['value'] = self.value.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "type": obj.get("type"),
            "booleanValue": obj.get("booleanValue"),
            "entity": obj.get("entity"),
            "floatValue": obj.get("floatValue"),
            "key": obj.get("key"),
            "name": obj.get("name"),
            "numberValue": obj.get("numberValue"),
            "operator": obj.get("operator"),
            "stringValue": obj.get("stringValue"),
            "value": TagFilterAllOfValue.from_dict(obj["value"]) if obj.get("value") is not None else None
        })
        return _obj


