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

class MetricInstance(BaseModel):
    """
    MetricInstance
    """ # noqa: E501
    custom: Optional[StrictBool] = None
    description: StrictStr
    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
    metric_id: StrictStr = Field(alias="metricId")
    plugin_id: StrictStr = Field(alias="pluginId")
    __properties: ClassVar[List[str]] = ["custom", "description", "formatter", "label", "metricId", "pluginId"]

    @field_validator('formatter')
    def formatter_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['NUMBER', 'BYTES', 'KILO_BYTES', 'MEGA_BYTES', 'PERCENTAGE', 'PERCENTAGE_100', 'PERCENTAGE_NO_CAPPING', 'PERCENTAGE_100_NO_CAPPING', 'LATENCY', 'NANOS', 'MILLIS', 'MICROS', 'SECONDS', 'RATE', 'BYTE_RATE', 'UNDEFINED']):
            raise ValueError("must be one of enum values ('NUMBER', 'BYTES', 'KILO_BYTES', 'MEGA_BYTES', 'PERCENTAGE', 'PERCENTAGE_100', 'PERCENTAGE_NO_CAPPING', 'PERCENTAGE_100_NO_CAPPING', 'LATENCY', 'NANOS', 'MILLIS', 'MICROS', 'SECONDS', 'RATE', 'BYTE_RATE', 'UNDEFINED')")
        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 MetricInstance 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 MetricInstance from a dict"""
        if obj is None:
            return None

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

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


