# coding: utf-8

"""
    Cloudera AI Inference

    CML Serving :: Install and manage CML Serving workloads.

    The version of the OpenAPI document: v1alpha1
    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
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class ServingAutoscalingConfig(BaseModel):
    """
    ServingAutoscalingConfig
    """ # noqa: E501
    metric: Optional[StrictStr] = Field(default=None, description="the metric that is to be watched to make autoscaling decisions.  Can be set to either RPS or Concurrency")
    target: Optional[StrictStr] = Field(default=None, description="the limit for the metric of each replica.  Each replica can only handle at most this target.  By default, the values are set at 200")
    target_utilization: Optional[StrictStr] = Field(default=None, description="a tuning of the target field to specify how \"hot\" each replica runs.  Set as a percentage, this will determine scale up sensitivitry")
    scale_to_zero_retention: Optional[StrictStr] = Field(default=None, description="tuning of how long after a scale to zero decision has been made that the pod should remain available before scaling down")
    activation_scale: Optional[StrictStr] = Field(default=None, description="the number of replicas that should be created when scaling up from zero")
    scale_down_delay: Optional[StrictStr] = Field(default=None, description="how long to wait before a scale down decision is made")
    panic_window_percentage: Optional[StrictStr] = Field(default=None, description="the size of the panic window as a percentage of the stable window")
    panic_threshold: Optional[StrictStr] = Field(default=None, description="the amount of traffic that each replica must be receiving before entering into panic mode: exceeding all limits and scaling to deal with short, high bursts of traffic")
    stable_window: Optional[StrictStr] = Field(default=None, description="the interval in which metrics are being scraped and processed to determine autoscaling decisions")
    __properties: ClassVar[List[str]] = ["metric", "target", "target_utilization", "scale_to_zero_retention", "activation_scale", "scale_down_delay", "panic_window_percentage", "panic_threshold", "stable_window"]

    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 ServingAutoscalingConfig 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 ServingAutoscalingConfig from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "metric": obj.get("metric"),
            "target": obj.get("target"),
            "target_utilization": obj.get("target_utilization"),
            "scale_to_zero_retention": obj.get("scale_to_zero_retention"),
            "activation_scale": obj.get("activation_scale"),
            "scale_down_delay": obj.get("scale_down_delay"),
            "panic_window_percentage": obj.get("panic_window_percentage"),
            "panic_threshold": obj.get("panic_threshold"),
            "stable_window": obj.get("stable_window")
        })
        return _obj


