# 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, StrictStr, conlist
from .v2_hpa_scaling_policy import V2HPAScalingPolicy

class V2HPAScalingRules(BaseModel):
    """
    HPAScalingRules configures the scaling behavior for one direction. These Rules are applied after calculating DesiredReplicas from metrics for the HPA. They can limit the scaling velocity by specifying scaling policies. They can prevent flapping by specifying the stabilization window, so that the number of replicas is not set instantly, instead, the safest value from the stabilization window is chosen.  # noqa: E501
    """
    policies: Optional[conlist(V2HPAScalingPolicy)] = Field(None, description="policies is a list of potential scaling polices which can be used during scaling. At least one policy must be specified, otherwise the HPAScalingRules will be discarded as invalid")
    select_policy: Optional[StrictStr] = Field(None, alias="selectPolicy", description="selectPolicy is used to specify which policy should be used. If not set, the default value Max is used.")
    stabilization_window_seconds: Optional[StrictInt] = Field(None, alias="stabilizationWindowSeconds", description="stabilizationWindowSeconds is the number of seconds for which past recommendations should be considered while scaling up or scaling down. StabilizationWindowSeconds must be greater than or equal to zero and less than or equal to 3600 (one hour). If not set, use the default values: - For scale up: 0 (i.e. no stabilization is done). - For scale down: 300 (i.e. the stabilization window is 300 seconds long).")
    __properties = ["policies", "selectPolicy", "stabilizationWindowSeconds"]

    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) -> V2HPAScalingRules:
        """Create an instance of V2HPAScalingRules 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 each item in policies (list)
        _items = []
        if self.policies:
            for _item in self.policies:
                if _item:
                    _items.append(_item.to_dict())
            _dict['policies'] = _items
        return _dict

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

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

        _obj = V2HPAScalingRules.parse_obj({
            "policies": [V2HPAScalingPolicy.from_dict(_item) for _item in obj.get("policies")] if obj.get("policies") is not None else None,
            "select_policy": obj.get("selectPolicy"),
            "stabilization_window_seconds": obj.get("stabilizationWindowSeconds")
        })
        return _obj


