// <auto-generated>
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>

namespace k8s.Models
{
    using Microsoft.Rest;
    using Newtonsoft.Json;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// HorizontalPodAutoscalerSpec describes the desired functionality of the
    /// HorizontalPodAutoscaler.
    /// </summary>
    public partial class V2beta1HorizontalPodAutoscalerSpec
    {
        /// <summary>
        /// Initializes a new instance of the
        /// V2beta1HorizontalPodAutoscalerSpec class.
        /// </summary>
        public V2beta1HorizontalPodAutoscalerSpec()
        {
            CustomInit();
        }

        /// <summary>
        /// Initializes a new instance of the
        /// V2beta1HorizontalPodAutoscalerSpec class.
        /// </summary>
        /// <param name="maxReplicas">maxReplicas is the upper limit for the
        /// number of replicas to which the autoscaler can scale up. It cannot
        /// be less that minReplicas.</param>
        /// <param name="scaleTargetRef">scaleTargetRef points to the target
        /// resource to scale, and is used to the pods for which metrics should
        /// be collected, as well as to actually change the replica
        /// count.</param>
        /// <param name="metrics">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.</param>
        /// <param name="minReplicas">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.</param>
        public V2beta1HorizontalPodAutoscalerSpec(int maxReplicas, V2beta1CrossVersionObjectReference scaleTargetRef, IList<V2beta1MetricSpec> metrics = default(IList<V2beta1MetricSpec>), int? minReplicas = default(int?))
        {
            MaxReplicas = maxReplicas;
            Metrics = metrics;
            MinReplicas = minReplicas;
            ScaleTargetRef = scaleTargetRef;
            CustomInit();
        }

        /// <summary>
        /// An initialization method that performs custom operations like setting defaults
        /// </summary>
        partial void CustomInit();

        /// <summary>
        /// Gets or sets maxReplicas is the upper limit for the number of
        /// replicas to which the autoscaler can scale up. It cannot be less
        /// that minReplicas.
        /// </summary>
        [JsonProperty(PropertyName = "maxReplicas")]
        public int MaxReplicas { get; set; }

        /// <summary>
        /// Gets or sets 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.
        /// </summary>
        [JsonProperty(PropertyName = "metrics")]
        public IList<V2beta1MetricSpec> Metrics { get; set; }

        /// <summary>
        /// Gets or sets 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.
        /// </summary>
        [JsonProperty(PropertyName = "minReplicas")]
        public int? MinReplicas { get; set; }

        /// <summary>
        /// Gets or sets scaleTargetRef points to the target resource to scale,
        /// and is used to the pods for which metrics should be collected, as
        /// well as to actually change the replica count.
        /// </summary>
        [JsonProperty(PropertyName = "scaleTargetRef")]
        public V2beta1CrossVersionObjectReference ScaleTargetRef { get; set; }

        /// <summary>
        /// Validate the object.
        /// </summary>
        /// <exception cref="ValidationException">
        /// Thrown if validation fails
        /// </exception>
        public virtual void Validate()
        {
            if (ScaleTargetRef == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "ScaleTargetRef");
            }
            if (Metrics != null)
            {
                foreach (var element in Metrics)
                {
                    if (element != null)
                    {
                        element.Validate();
                    }
                }
            }
            if (ScaleTargetRef != null)
            {
                ScaleTargetRef.Validate();
            }
        }
    }
}
