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

// BGPFilterRuleV4ApplyConfiguration represents a declarative configuration of the BGPFilterRuleV4 type for use
// with apply.
//
// BGPFilterRuleV4 defines a BGP filter rule consisting of match criteria, a terminal action,
// and optional operations to apply to matching routes.
type BGPFilterRuleV4ApplyConfiguration struct {
	// If non-empty, this filter rule will only apply when the route being exported or imported
	// "matches" the given CIDR - where the definition of "matches" is according to
	// MatchOperator and PrefixLength.  CIDR should be in conventional CIDR notation,
	// <prefix>/<length>.
	CIDR *string `json:"cidr,omitempty"`
	// PrefixLength further constrains the CIDR match by restricting the range of allowed
	// prefix lengths.  For example, CIDR "10.0.0.0/8" with MatchOperator "In" and
	// PrefixLength {min: 16, max: 24} matches any route within 10.0.0.0/8 whose prefix
	// length is between /16 and /24.  Requires CIDR to be set; if CIDR is omitted,
	// PrefixLength is ignored.  If PrefixLength is nil and CIDR is set, the CIDR's own
	// prefix length is used as the minimum and /32 (for V4) as the maximum.
	PrefixLength *BGPFilterPrefixLengthV4ApplyConfiguration `json:"prefixLength,omitempty"`
	// If set to "RemotePeers": for export rules, this filter rule will only apply to routes
	// learned from BGP peers (i.e. re-advertised routes), not locally originated routes.
	// For import rules, this field is redundant because imported routes are by definition
	// from BGP peers.
	Source *projectcalicov3.BGPFilterMatchSource `json:"source,omitempty"`
	// If non-empty, this filter rule will only apply to routes with an outgoing interface that
	// matches Interface.
	Interface *string `json:"interface,omitempty"`
	// MatchOperator defines how the route's prefix is compared against CIDR.  "Equal" requires
	// an exact prefix match, "In" requires the route to be contained within the CIDR (or equal),
	// "NotEqual" and "NotIn" are their negations.  Only meaningful when CIDR is also specified.
	// Required when CIDR is set.
	MatchOperator *projectcalicov3.BGPFilterMatchOperator `json:"matchOperator,omitempty"`
	// If non-empty, this filter rule will only apply to routes being imported from or exported
	// to a BGP peer of the specified type.  If empty, the rule applies to all peers.
	PeerType *projectcalicov3.BGPFilterPeerType `json:"peerType,omitempty"`
	// If set, this filter rule will only apply to routes that carry the specified BGP
	// community.  On import, this matches communities set by the remote peer.  On export,
	// this matches communities already present on the route, whether received from a BGP
	// peer (e.g. on a route reflector re-advertising to an eBGP peer) or added locally
	// by an import filter or an earlier export rule's AddCommunity operation.
	Communities *BGPFilterCommunityMatchApplyConfiguration `json:"communities,omitempty"`
	// If non-empty, this filter rule will only apply to routes whose AS path begins with the
	// specified sequence of AS numbers.
	ASPathPrefix []numorstring.ASNumber `json:"asPathPrefix,omitempty"`
	// If set, this filter rule will only apply to routes with the given priority, in the
	// same units as the ...RoutePriority fields in FelixConfiguration.
	Priority *int                             `json:"priority,omitempty"`
	Action   *projectcalicov3.BGPFilterAction `json:"action,omitempty"`
	// Operations is an ordered list of route modifications to apply to matching routes before
	// accepting them.  Only valid when Action is "Accept"; specifying operations with "Reject"
	// is rejected by validation.  Each entry must set exactly one operation field.
	Operations []BGPFilterOperationApplyConfiguration `json:"operations,omitempty"`
}

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

// WithCIDR sets the CIDR 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 CIDR field is set to the value of the last call.
func (b *BGPFilterRuleV4ApplyConfiguration) WithCIDR(value string) *BGPFilterRuleV4ApplyConfiguration {
	b.CIDR = &value
	return b
}

// WithPrefixLength sets the PrefixLength 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 PrefixLength field is set to the value of the last call.
func (b *BGPFilterRuleV4ApplyConfiguration) WithPrefixLength(value *BGPFilterPrefixLengthV4ApplyConfiguration) *BGPFilterRuleV4ApplyConfiguration {
	b.PrefixLength = 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 *BGPFilterRuleV4ApplyConfiguration) WithSource(value projectcalicov3.BGPFilterMatchSource) *BGPFilterRuleV4ApplyConfiguration {
	b.Source = &value
	return b
}

// WithInterface sets the Interface 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 Interface field is set to the value of the last call.
func (b *BGPFilterRuleV4ApplyConfiguration) WithInterface(value string) *BGPFilterRuleV4ApplyConfiguration {
	b.Interface = &value
	return b
}

// WithMatchOperator sets the MatchOperator 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 MatchOperator field is set to the value of the last call.
func (b *BGPFilterRuleV4ApplyConfiguration) WithMatchOperator(value projectcalicov3.BGPFilterMatchOperator) *BGPFilterRuleV4ApplyConfiguration {
	b.MatchOperator = &value
	return b
}

// WithPeerType sets the PeerType 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 PeerType field is set to the value of the last call.
func (b *BGPFilterRuleV4ApplyConfiguration) WithPeerType(value projectcalicov3.BGPFilterPeerType) *BGPFilterRuleV4ApplyConfiguration {
	b.PeerType = &value
	return b
}

// WithCommunities sets the Communities 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 Communities field is set to the value of the last call.
func (b *BGPFilterRuleV4ApplyConfiguration) WithCommunities(value *BGPFilterCommunityMatchApplyConfiguration) *BGPFilterRuleV4ApplyConfiguration {
	b.Communities = value
	return b
}

// WithASPathPrefix adds the given value to the ASPathPrefix 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 ASPathPrefix field.
func (b *BGPFilterRuleV4ApplyConfiguration) WithASPathPrefix(values ...numorstring.ASNumber) *BGPFilterRuleV4ApplyConfiguration {
	for i := range values {
		b.ASPathPrefix = append(b.ASPathPrefix, values[i])
	}
	return b
}

// WithPriority sets the Priority 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 Priority field is set to the value of the last call.
func (b *BGPFilterRuleV4ApplyConfiguration) WithPriority(value int) *BGPFilterRuleV4ApplyConfiguration {
	b.Priority = &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 *BGPFilterRuleV4ApplyConfiguration) WithAction(value projectcalicov3.BGPFilterAction) *BGPFilterRuleV4ApplyConfiguration {
	b.Action = &value
	return b
}

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