# coding: utf-8

"""
    Kubernetes

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: release-1.29
    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 typing import List, Optional
from pydantic import BaseModel, Field, StrictInt, conlist
from .v2_cross_version_object_reference import V2CrossVersionObjectReference
from .v2_horizontal_pod_autoscaler_behavior import V2HorizontalPodAutoscalerBehavior
from .v2_metric_spec import V2MetricSpec

class V2HorizontalPodAutoscalerSpec(BaseModel):
    """
    HorizontalPodAutoscalerSpec describes the desired functionality of the HorizontalPodAutoscaler.  # noqa: E501
    """
    behavior: Optional[V2HorizontalPodAutoscalerBehavior] = None
    max_replicas: StrictInt = Field(..., alias="maxReplicas", description="maxReplicas is the upper limit for the number of replicas to which the autoscaler can scale up. It cannot be less that minReplicas.")
    metrics: Optional[conlist(V2MetricSpec)] = Field(None, description="metrics contains the specifications for which to use to calculate the desired replica count (the maximum replica count across all metrics will be used).  The desired replica count is calculated multiplying the ratio between the target value and the current value by the current number of pods.  Ergo, metrics used must decrease as the pod count is increased, and vice-versa.  See the individual metric source types for more information about how each type of metric must respond. If not set, the default metric will be set to 80% average CPU utilization.")
    min_replicas: Optional[StrictInt] = Field(None, alias="minReplicas", description="minReplicas is the lower limit for the number of replicas to which the autoscaler can scale down.  It defaults to 1 pod.  minReplicas is allowed to be 0 if the alpha feature gate HPAScaleToZero is enabled and at least one Object or External metric is configured.  Scaling is active as long as at least one metric value is available.")
    scale_target_ref: V2CrossVersionObjectReference = Field(..., alias="scaleTargetRef")
    __properties = ["behavior", "maxReplicas", "metrics", "minReplicas", "scaleTargetRef"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> V2HorizontalPodAutoscalerSpec:
        """Create an instance of V2HorizontalPodAutoscalerSpec from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of behavior
        if self.behavior:
            _dict['behavior'] = self.behavior.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in metrics (list)
        _items = []
        if self.metrics:
            for _item in self.metrics:
                if _item:
                    _items.append(_item.to_dict())
            _dict['metrics'] = _items
        # override the default output from pydantic by calling `to_dict()` of scale_target_ref
        if self.scale_target_ref:
            _dict['scaleTargetRef'] = self.scale_target_ref.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> V2HorizontalPodAutoscalerSpec:
        """Create an instance of V2HorizontalPodAutoscalerSpec from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return V2HorizontalPodAutoscalerSpec.parse_obj(obj)

        _obj = V2HorizontalPodAutoscalerSpec.parse_obj({
            "behavior": V2HorizontalPodAutoscalerBehavior.from_dict(obj.get("behavior")) if obj.get("behavior") is not None else None,
            "max_replicas": obj.get("maxReplicas"),
            "metrics": [V2MetricSpec.from_dict(_item) for _item in obj.get("metrics")] if obj.get("metrics") is not None else None,
            "min_replicas": obj.get("minReplicas"),
            "scale_target_ref": V2CrossVersionObjectReference.from_dict(obj.get("scaleTargetRef")) if obj.get("scaleTargetRef") is not None else None
        })
        return _obj


