# 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 CustomMetric(BaseModel):
    """
    CustomMetric
    """ # noqa: E501
    aggregation: Optional[StrictStr] = Field(default=None, description="Aggregation to apply on the metric for every member.")
    category: Optional[StrictStr] = Field(default=None, description="Category of the metric in the catalog")
    description: Optional[StrictStr] = Field(default=None, description="Description to be used in the catalog")
    formatter: Optional[StrictStr] = Field(default=None, 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: Optional[StrictStr] = Field(default=None, description="Label to be used in the catalog")
    name: Optional[StrictStr] = Field(default=None, description="Name of the metric")
    section: Optional[StrictStr] = Field(default=None, description="Section of the metric in the catalog")
    source: Optional[StrictStr] = Field(default=None, description="Name of the source metric")
    type: Optional[StrictStr] = Field(default=None, description="Type of entity for the source metric")
    __properties: ClassVar[List[str]] = ["aggregation", "category", "description", "formatter", "label", "name", "section", "source", "type"]

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

        if value not in set(['AVG', 'SUM']):
            raise ValueError("must be one of enum values ('AVG', 'SUM')")
        return value

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

        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

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

        if value not in set(['ACE', 'ALICLOUD', 'AWS', 'AZURE', 'CASSANDRA', 'CLOUD_FOUNDRY', 'CLR', 'COCKROACH', 'CONSUL', 'CONTAINER', 'COUCHBASE', 'DFQ', 'ELASTICSEARCH', 'GCP', 'HADOOP_YARN', 'HAZELCAST', 'IBM_CLOUD', 'IBM_DATAPOWER', 'IBM_I_SERIES', 'IBM_MQ', 'IBM_MQMFT', 'IBM_OPENSTACK', 'KAFKA_CONNECT', 'KUBERNETES', 'MONGO_DB', 'OTHERS', 'REDIS', 'SAP', 'SELF_MONITORING', 'SOLR', 'SPARK', 'TIBCOBW', 'TUXEDO', 'VSHPERE', 'WEBSPHERE', 'CUSTOM_ENTITY']):
            raise ValueError("must be one of enum values ('ACE', 'ALICLOUD', 'AWS', 'AZURE', 'CASSANDRA', 'CLOUD_FOUNDRY', 'CLR', 'COCKROACH', 'CONSUL', 'CONTAINER', 'COUCHBASE', 'DFQ', 'ELASTICSEARCH', 'GCP', 'HADOOP_YARN', 'HAZELCAST', 'IBM_CLOUD', 'IBM_DATAPOWER', 'IBM_I_SERIES', 'IBM_MQ', 'IBM_MQMFT', 'IBM_OPENSTACK', 'KAFKA_CONNECT', 'KUBERNETES', 'MONGO_DB', 'OTHERS', 'REDIS', 'SAP', 'SELF_MONITORING', 'SOLR', 'SPARK', 'TIBCOBW', 'TUXEDO', 'VSHPERE', 'WEBSPHERE', 'CUSTOM_ENTITY')")
        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 CustomMetric 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 CustomMetric from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "aggregation": obj.get("aggregation"),
            "category": obj.get("category"),
            "description": obj.get("description"),
            "formatter": obj.get("formatter"),
            "label": obj.get("label"),
            "name": obj.get("name"),
            "section": obj.get("section"),
            "source": obj.get("source"),
            "type": obj.get("type")
        })
        return _obj


