// <auto-generated>
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// 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 Microsoft.Azure.Management.ServiceFabricManagedClusters.Models
{
    using Microsoft.Rest;
    using Newtonsoft.Json;
    using System.Linq;

    /// <summary>
    /// Describes a load balancing rule.
    /// </summary>
    public partial class LoadBalancingRule
    {
        /// <summary>
        /// Initializes a new instance of the LoadBalancingRule class.
        /// </summary>
        public LoadBalancingRule()
        {
            CustomInit();
        }

        /// <summary>
        /// Initializes a new instance of the LoadBalancingRule class.
        /// </summary>
        /// <param name="frontendPort">The port for the external endpoint. Port
        /// numbers for each rule must be unique within the Load Balancer.
        /// Acceptable values are between 1 and 65534.</param>
        /// <param name="backendPort">The port used for internal connections on
        /// the endpoint. Acceptable values are between 1 and 65535.</param>
        /// <param name="protocol">The reference to the transport protocol used
        /// by the load balancing rule. Possible values include: 'tcp',
        /// 'udp'</param>
        /// <param name="probeProtocol">the reference to the load balancer
        /// probe used by the load balancing rule. Possible values include:
        /// 'tcp', 'http', 'https'</param>
        /// <param name="probePort">The prob port used by the load balancing
        /// rule. Acceptable values are between 1 and 65535.</param>
        /// <param name="probeRequestPath">The probe request path. Only
        /// supported for HTTP/HTTPS probes.</param>
        public LoadBalancingRule(int frontendPort, int backendPort, string protocol, string probeProtocol, int? probePort = default(int?), string probeRequestPath = default(string))
        {
            FrontendPort = frontendPort;
            BackendPort = backendPort;
            Protocol = protocol;
            ProbePort = probePort;
            ProbeProtocol = probeProtocol;
            ProbeRequestPath = probeRequestPath;
            CustomInit();
        }

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

        /// <summary>
        /// Gets or sets the port for the external endpoint. Port numbers for
        /// each rule must be unique within the Load Balancer. Acceptable
        /// values are between 1 and 65534.
        /// </summary>
        [JsonProperty(PropertyName = "frontendPort")]
        public int FrontendPort { get; set; }

        /// <summary>
        /// Gets or sets the port used for internal connections on the
        /// endpoint. Acceptable values are between 1 and 65535.
        /// </summary>
        [JsonProperty(PropertyName = "backendPort")]
        public int BackendPort { get; set; }

        /// <summary>
        /// Gets or sets the reference to the transport protocol used by the
        /// load balancing rule. Possible values include: 'tcp', 'udp'
        /// </summary>
        [JsonProperty(PropertyName = "protocol")]
        public string Protocol { get; set; }

        /// <summary>
        /// Gets or sets the prob port used by the load balancing rule.
        /// Acceptable values are between 1 and 65535.
        /// </summary>
        [JsonProperty(PropertyName = "probePort")]
        public int? ProbePort { get; set; }

        /// <summary>
        /// Gets or sets the reference to the load balancer probe used by the
        /// load balancing rule. Possible values include: 'tcp', 'http',
        /// 'https'
        /// </summary>
        [JsonProperty(PropertyName = "probeProtocol")]
        public string ProbeProtocol { get; set; }

        /// <summary>
        /// Gets or sets the probe request path. Only supported for HTTP/HTTPS
        /// probes.
        /// </summary>
        [JsonProperty(PropertyName = "probeRequestPath")]
        public string ProbeRequestPath { get; set; }

        /// <summary>
        /// Validate the object.
        /// </summary>
        /// <exception cref="ValidationException">
        /// Thrown if validation fails
        /// </exception>
        public virtual void Validate()
        {
            if (Protocol == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "Protocol");
            }
            if (ProbeProtocol == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "ProbeProtocol");
            }
            if (FrontendPort > 65534)
            {
                throw new ValidationException(ValidationRules.InclusiveMaximum, "FrontendPort", 65534);
            }
            if (FrontendPort < 1)
            {
                throw new ValidationException(ValidationRules.InclusiveMinimum, "FrontendPort", 1);
            }
            if (BackendPort > 65534)
            {
                throw new ValidationException(ValidationRules.InclusiveMaximum, "BackendPort", 65534);
            }
            if (BackendPort < 1)
            {
                throw new ValidationException(ValidationRules.InclusiveMinimum, "BackendPort", 1);
            }
            if (ProbePort > 65534)
            {
                throw new ValidationException(ValidationRules.InclusiveMaximum, "ProbePort", 65534);
            }
            if (ProbePort < 1)
            {
                throw new ValidationException(ValidationRules.InclusiveMinimum, "ProbePort", 1);
            }
        }
    }
}
