# 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 import Optional, Set
from typing_extensions import Self

class MetricDescription(BaseModel):
    """
    MetricDescription
    """ # noqa: E501
    aggregations: List[StrictStr] = Field(description="The types of aggregations that can be applied to a series of values. For example, `P25` is 25th percentile. Note that not all aggregations are available for metrics. For example, `Trace count` has only `SUM` as an aggregation whereas `Call Count` has two aggregations, `SUM` and `PER_SECOND`. ")
    default_aggregation: Optional[StrictStr] = Field(default=None, description="The preselected aggregation for a metric. For example, for `Call latency` the default aggregation is `MEAN`.", alias="defaultAggregation")
    description: Optional[StrictStr] = Field(default=None, description="A description of the metric. For example, for `Call count` metric, the description would be something like `Number of received calls`")
    formatter: StrictStr = Field(description="* `NUMBER`: Generic number * `BYTES`: Number of bytes * `KILO_BYTES`: Number of kilobytes * `MEGA_BYTES`: Number of megabytes * `PERCENTAGE`: Percentage in scale [0,1] * `PERCENTAGE_100`: Percentage in scale [0,100] * `PERCENTAGE_NO_CAPPING`: Percentage in scale [0,1] but value could exceed 1 for example when metric is aggregated * `PERCENTAGE_100_NO_CAPPING`: Percentage in scale [0,100] but value could exceed 100 for example when metric is aggregated * `LATENCY`: Time in milliseconds, with value of 0 should not be considered a a strict 0, but considered as < 1ms * `NANOS`: Time in nanoseconds * `MILLIS`: Time in milliseconds * `MICROS`: Time in microseconds * `SECONDS`: Time in seconds * `RATE`: Number of occurrences per second * `BYTE_RATE`: Number of bytes per second * `UNDEFINED`: Metric value unit is not known ")
    label: StrictStr = Field(description="The name of the metric. For example, `Call count`, `Erroneous calls`, `Service count` etc.")
    metric_id: StrictStr = Field(description="The unique id of the metric. For example, `calls`, `erroneousCalls`, `latency` etc.", alias="metricId")
    __properties: ClassVar[List[str]] = ["aggregations", "defaultAggregation", "description", "formatter", "label", "metricId"]

    @field_validator('aggregations')
    def aggregations_validate_enum(cls, value):
        """Validates the enum"""
        for i in value:
            if i not in set(['SUM', 'MEAN', 'MAX', 'MIN', 'P25', 'P50', 'P75', 'P90', 'P95', 'P98', 'P99', 'P99_9', 'P99_99', 'DISTINCT_COUNT', 'SUM_POSITIVE', 'PER_SECOND', 'INCREASE']):
                raise ValueError("each list item must be one of ('SUM', 'MEAN', 'MAX', 'MIN', 'P25', 'P50', 'P75', 'P90', 'P95', 'P98', 'P99', 'P99_9', 'P99_99', 'DISTINCT_COUNT', 'SUM_POSITIVE', 'PER_SECOND', 'INCREASE')")
        return value

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

        if value not in set(['SUM', 'MEAN', 'MAX', 'MIN', 'P25', 'P50', 'P75', 'P90', 'P95', 'P98', 'P99', 'P99_9', 'P99_99', 'DISTINCT_COUNT', 'SUM_POSITIVE', 'PER_SECOND', 'INCREASE']):
            raise ValueError("must be one of enum values ('SUM', 'MEAN', 'MAX', 'MIN', 'P25', 'P50', 'P75', 'P90', 'P95', 'P98', 'P99', 'P99_9', 'P99_99', 'DISTINCT_COUNT', 'SUM_POSITIVE', 'PER_SECOND', 'INCREASE')")
        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 MetricDescription 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 MetricDescription from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "aggregations": obj.get("aggregations"),
            "defaultAggregation": obj.get("defaultAggregation"),
            "description": obj.get("description"),
            "formatter": obj.get("formatter"),
            "label": obj.get("label"),
            "metricId": obj.get("metricId")
        })
        return _obj


