/*
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"
)

// BaselineAdminNetworkPolicyEgressRuleApplyConfiguration represents a declarative configuration of the BaselineAdminNetworkPolicyEgressRule type for use
// with apply.
//
// BaselineAdminNetworkPolicyEgressRule describes an action to take on a particular
// set of traffic originating from pods selected by a BaselineAdminNetworkPolicy's
// Subject field.
// <network-policy-api:experimental:validation>
type BaselineAdminNetworkPolicyEgressRuleApplyConfiguration 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"`
	// To is the list of destinations whose traffic this rule applies to.
	// If any element matches the destination of outgoing
	// traffic then the specified action is applied.
	// This field must be defined and contain at least one item.
	To []BaselineAdminNetworkPolicyEgressPeerApplyConfiguration `json:"to,omitempty"`
	// Ports allows for matching traffic based on port and protocols.
	// This field is a list of destination ports for the outgoing egress traffic.
	// If Ports is not set then the rule does not filter traffic via port.
	Ports *[]AdminNetworkPolicyPortApplyConfiguration `json:"ports,omitempty"`
}

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

// 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 *BaselineAdminNetworkPolicyEgressRuleApplyConfiguration) WithName(value string) *BaselineAdminNetworkPolicyEgressRuleApplyConfiguration {
	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 *BaselineAdminNetworkPolicyEgressRuleApplyConfiguration) WithAction(value apisv1alpha1.BaselineAdminNetworkPolicyRuleAction) *BaselineAdminNetworkPolicyEgressRuleApplyConfiguration {
	b.Action = &value
	return b
}

// WithTo adds the given value to the To 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 To field.
func (b *BaselineAdminNetworkPolicyEgressRuleApplyConfiguration) WithTo(values ...*BaselineAdminNetworkPolicyEgressPeerApplyConfiguration) *BaselineAdminNetworkPolicyEgressRuleApplyConfiguration {
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithTo")
		}
		b.To = append(b.To, *values[i])
	}
	return b
}

func (b *BaselineAdminNetworkPolicyEgressRuleApplyConfiguration) 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 *BaselineAdminNetworkPolicyEgressRuleApplyConfiguration) WithPorts(values ...*AdminNetworkPolicyPortApplyConfiguration) *BaselineAdminNetworkPolicyEgressRuleApplyConfiguration {
	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
}
