// Copyright (c) 2026 Tigera, Inc. All rights reserved.

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

package v3

import (
	projectcalicov3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
	numorstring "github.com/projectcalico/api/pkg/lib/numorstring"
)

// RuleApplyConfiguration represents a declarative configuration of the Rule type for use
// with apply.
//
// A Rule encapsulates a set of match criteria and an action.  Both selector-based security Policy
// and security Profiles reference rules - separated out as a list of rules for both
// ingress and egress packet matching.
//
// Each positive match criteria has a negated version, prefixed with "Not". All the match
// criteria within a rule must be satisfied for a packet to match. A single rule can contain
// the positive and negative version of a match and both must be satisfied for the rule to match.
type RuleApplyConfiguration struct {
	Action *projectcalicov3.Action `json:"action,omitempty"`
	// IPVersion is an optional field that restricts the rule to only match a specific IP
	// version.
	IPVersion *int `json:"ipVersion,omitempty"`
	// Protocol is an optional field that restricts the rule to only apply to traffic of
	// a specific IP protocol. Required if any of the EntityRules contain Ports
	// (because ports only apply to certain protocols).
	//
	// Must be one of these string values: "TCP", "UDP", "ICMP", "ICMPv6", "SCTP", "UDPLite"
	// or an integer in the range 1-255.
	Protocol *numorstring.Protocol `json:"protocol,omitempty"`
	// ICMP is an optional field that restricts the rule to apply to a specific type and
	// code of ICMP traffic.  This should only be specified if the Protocol field is set to
	// "ICMP" or "ICMPv6".
	ICMP *ICMPFieldsApplyConfiguration `json:"icmp,omitempty"`
	// NotProtocol is the negated version of the Protocol field.
	NotProtocol *numorstring.Protocol `json:"notProtocol,omitempty"`
	// NotICMP is the negated version of the ICMP field.
	NotICMP *ICMPFieldsApplyConfiguration `json:"notICMP,omitempty"`
	// Source contains the match criteria that apply to source entity.
	Source *EntityRuleApplyConfiguration `json:"source,omitempty"`
	// Destination contains the match criteria that apply to destination entity.
	Destination *EntityRuleApplyConfiguration `json:"destination,omitempty"`
	// HTTP contains match criteria that apply to HTTP requests.
	HTTP *HTTPMatchApplyConfiguration `json:"http,omitempty"`
	// Metadata contains additional information for this rule
	Metadata *RuleMetadataApplyConfiguration `json:"metadata,omitempty"`
}

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

// 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 *RuleApplyConfiguration) WithAction(value projectcalicov3.Action) *RuleApplyConfiguration {
	b.Action = &value
	return b
}

// WithIPVersion sets the IPVersion 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 IPVersion field is set to the value of the last call.
func (b *RuleApplyConfiguration) WithIPVersion(value int) *RuleApplyConfiguration {
	b.IPVersion = &value
	return b
}

// WithProtocol sets the Protocol 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 Protocol field is set to the value of the last call.
func (b *RuleApplyConfiguration) WithProtocol(value numorstring.Protocol) *RuleApplyConfiguration {
	b.Protocol = &value
	return b
}

// WithICMP sets the ICMP 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 ICMP field is set to the value of the last call.
func (b *RuleApplyConfiguration) WithICMP(value *ICMPFieldsApplyConfiguration) *RuleApplyConfiguration {
	b.ICMP = value
	return b
}

// WithNotProtocol sets the NotProtocol 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 NotProtocol field is set to the value of the last call.
func (b *RuleApplyConfiguration) WithNotProtocol(value numorstring.Protocol) *RuleApplyConfiguration {
	b.NotProtocol = &value
	return b
}

// WithNotICMP sets the NotICMP 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 NotICMP field is set to the value of the last call.
func (b *RuleApplyConfiguration) WithNotICMP(value *ICMPFieldsApplyConfiguration) *RuleApplyConfiguration {
	b.NotICMP = value
	return b
}

// WithSource sets the Source 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 Source field is set to the value of the last call.
func (b *RuleApplyConfiguration) WithSource(value *EntityRuleApplyConfiguration) *RuleApplyConfiguration {
	b.Source = value
	return b
}

// WithDestination sets the Destination 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 Destination field is set to the value of the last call.
func (b *RuleApplyConfiguration) WithDestination(value *EntityRuleApplyConfiguration) *RuleApplyConfiguration {
	b.Destination = value
	return b
}

// WithHTTP sets the HTTP 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 HTTP field is set to the value of the last call.
func (b *RuleApplyConfiguration) WithHTTP(value *HTTPMatchApplyConfiguration) *RuleApplyConfiguration {
	b.HTTP = value
	return b
}

// WithMetadata sets the Metadata 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 Metadata field is set to the value of the last call.
func (b *RuleApplyConfiguration) WithMetadata(value *RuleMetadataApplyConfiguration) *RuleApplyConfiguration {
	b.Metadata = value
	return b
}
