// <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>
    /// PolicyRulesWithSubjects prescribes a test that applies to a request to
    /// an apiserver. The test considers the subject making the request, the
    /// verb being requested, and the resource to be acted upon. This
    /// PolicyRulesWithSubjects matches a request if and only if both (a) at
    /// least one member of subjects matches the request and (b) at least one
    /// member of resourceRules or nonResourceRules matches the request.
    /// </summary>
    public partial class V1beta1PolicyRulesWithSubjects
    {
        /// <summary>
        /// Initializes a new instance of the V1beta1PolicyRulesWithSubjects
        /// class.
        /// </summary>
        public V1beta1PolicyRulesWithSubjects()
        {
            CustomInit();
        }

        /// <summary>
        /// Initializes a new instance of the V1beta1PolicyRulesWithSubjects
        /// class.
        /// </summary>
        /// <param name="subjects">subjects is the list of normal user,
        /// serviceaccount, or group that this rule cares about. There must be
        /// at least one member in this slice. A slice that includes both the
        /// system:authenticated and system:unauthenticated user groups matches
        /// every request. Required.</param>
        /// <param name="nonResourceRules">`nonResourceRules` is a list of
        /// NonResourcePolicyRules that identify matching requests according to
        /// their verb and the target non-resource URL.</param>
        /// <param name="resourceRules">`resourceRules` is a slice of
        /// ResourcePolicyRules that identify matching requests according to
        /// their verb and the target resource. At least one of `resourceRules`
        /// and `nonResourceRules` has to be non-empty.</param>
        public V1beta1PolicyRulesWithSubjects(IList<Flowcontrolv1beta1Subject> subjects, IList<V1beta1NonResourcePolicyRule> nonResourceRules = default(IList<V1beta1NonResourcePolicyRule>), IList<V1beta1ResourcePolicyRule> resourceRules = default(IList<V1beta1ResourcePolicyRule>))
        {
            NonResourceRules = nonResourceRules;
            ResourceRules = resourceRules;
            Subjects = subjects;
            CustomInit();
        }

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

        /// <summary>
        /// Gets or sets `nonResourceRules` is a list of NonResourcePolicyRules
        /// that identify matching requests according to their verb and the
        /// target non-resource URL.
        /// </summary>
        [JsonProperty(PropertyName = "nonResourceRules")]
        public IList<V1beta1NonResourcePolicyRule> NonResourceRules { get; set; }

        /// <summary>
        /// Gets or sets `resourceRules` is a slice of ResourcePolicyRules that
        /// identify matching requests according to their verb and the target
        /// resource. At least one of `resourceRules` and `nonResourceRules`
        /// has to be non-empty.
        /// </summary>
        [JsonProperty(PropertyName = "resourceRules")]
        public IList<V1beta1ResourcePolicyRule> ResourceRules { get; set; }

        /// <summary>
        /// Gets or sets subjects is the list of normal user, serviceaccount,
        /// or group that this rule cares about. There must be at least one
        /// member in this slice. A slice that includes both the
        /// system:authenticated and system:unauthenticated user groups matches
        /// every request. Required.
        /// </summary>
        [JsonProperty(PropertyName = "subjects")]
        public IList<Flowcontrolv1beta1Subject> Subjects { get; set; }

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