# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class SyntheticMetricTagGroup(BaseModel):
    """
     Grouping of data under `groupbyTag`, where `groupbyTagEntity` and `groupbyTagSecondLevelKey` are aspects of `groupbyTag`.
    """ # noqa: E501
    direction: StrictStr
    groupby_tag: Annotated[str, Field(min_length=0, strict=True, max_length=256)] = Field(description="The name of the group tag (e.g. `agent.tag` or `docker.label`).", alias="groupbyTag")
    groupby_tag_entity: StrictStr = Field(description="The entity by which the data should be grouped. This field supports three possible values: `NOT_APPLICABLE`, `DESTINATION`, and `SOURCE`. `SOURCE`: the tag filter should apply to the source entity. `DESTINATION`: the tag filter should apply to the destination entity. `NOT_APPLICABLE`: some tags are independent of source or destination, such as tags on the call itself, log tags or trace tags (only destination makes sense because the source is unknown for the root call). ", alias="groupbyTagEntity")
    groupby_tag_second_level_key: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=256)]] = Field(default=None, description="If present, it's the 2nd level key part (e.g. `customKey` on `docker.label.customKey`)", alias="groupbyTagSecondLevelKey")
    include_others: Optional[StrictBool] = Field(default=None, alias="includeOthers")
    max_results: Optional[Annotated[int, Field(le=50, strict=True, ge=1)]] = Field(default=None, alias="maxResults")
    __properties: ClassVar[List[str]] = ["direction", "groupbyTag", "groupbyTagEntity", "groupbyTagSecondLevelKey", "includeOthers", "maxResults"]

    @field_validator('direction')
    def direction_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['ASC', 'DESC']):
            raise ValueError("must be one of enum values ('ASC', 'DESC')")
        return value

    @field_validator('groupby_tag_entity')
    def groupby_tag_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

    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 SyntheticMetricTagGroup 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: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of SyntheticMetricTagGroup from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "direction": obj.get("direction"),
            "groupbyTag": obj.get("groupbyTag"),
            "groupbyTagEntity": obj.get("groupbyTagEntity"),
            "groupbyTagSecondLevelKey": obj.get("groupbyTagSecondLevelKey"),
            "includeOthers": obj.get("includeOthers"),
            "maxResults": obj.get("maxResults")
        })
        return _obj


