/*
Copyright The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Code generated by applyconfiguration-gen. DO NOT EDIT.

package v1alpha1

import (
	apisv1alpha1 "sigs.k8s.io/network-policy-api/apis/v1alpha1"
)

// BaselineAdminNetworkPolicyIngressRuleApplyConfiguration represents a declarative configuration of the BaselineAdminNetworkPolicyIngressRule type for use
// with apply.
//
// BaselineAdminNetworkPolicyIngressRule describes an action to take on a particular
// set of traffic destined for pods selected by a BaselineAdminNetworkPolicy's
// Subject field.
type BaselineAdminNetworkPolicyIngressRuleApplyConfiguration struct {
	// Name is an identifier for this rule, that may be no more than 100 characters
	// in length. This field should be used by the implementation to help
	// improve observability, readability and error-reporting for any applied
	// BaselineAdminNetworkPolicies.
	Name *string `json:"name,omitempty"`
	// Action specifies the effect this rule will have on matching traffic.
	// Currently the following actions are supported:
	// Allow: allows the selected traffic
	// Deny: denies the selected traffic
	Action *apisv1alpha1.BaselineAdminNetworkPolicyRuleAction `json:"action,omitempty"`
	// From is the list of sources whose traffic this rule applies to.
	// If any element matches the source of incoming
	// traffic then the specified action is applied.
	// This field must be defined and contain at least one item.
	From []AdminNetworkPolicyIngressPeerApplyConfiguration `json:"from,omitempty"`
	// Ports allows for matching traffic based on port and protocols.
	// This field is a list of ports which should be matched on
	// the pods selected for this policy i.e the subject of the policy.
	// So it matches on the destination port for the ingress traffic.
	// If Ports is not set then the rule does not filter traffic via port.
	Ports *[]AdminNetworkPolicyPortApplyConfiguration `json:"ports,omitempty"`
}

// BaselineAdminNetworkPolicyIngressRuleApplyConfiguration constructs a declarative configuration of the BaselineAdminNetworkPolicyIngressRule type for use with
// apply.
func BaselineAdminNetworkPolicyIngressRule() *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration {
	return &BaselineAdminNetworkPolicyIngressRuleApplyConfiguration{}
}

// WithName sets the Name field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Name field is set to the value of the last call.
func (b *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration) WithName(value string) *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration {
	b.Name = &value
	return b
}

// WithAction sets the Action field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Action field is set to the value of the last call.
func (b *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration) WithAction(value apisv1alpha1.BaselineAdminNetworkPolicyRuleAction) *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration {
	b.Action = &value
	return b
}

// WithFrom adds the given value to the From field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the From field.
func (b *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration) WithFrom(values ...*AdminNetworkPolicyIngressPeerApplyConfiguration) *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration {
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithFrom")
		}
		b.From = append(b.From, *values[i])
	}
	return b
}

func (b *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration) ensureAdminNetworkPolicyPortApplyConfigurationExists() {
	if b.Ports == nil {
		b.Ports = &[]AdminNetworkPolicyPortApplyConfiguration{}
	}
}

// WithPorts adds the given value to the Ports field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the Ports field.
func (b *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration) WithPorts(values ...*AdminNetworkPolicyPortApplyConfiguration) *BaselineAdminNetworkPolicyIngressRuleApplyConfiguration {
	b.ensureAdminNetworkPolicyPortApplyConfigurationExists()
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithPorts")
		}
		*b.Ports = append(*b.Ports, *values[i])
	}
	return b
}
