// 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"
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// BGPPeerSpecApplyConfiguration represents a declarative configuration of the BGPPeerSpec type for use
// with apply.
//
// BGPPeerSpec contains the specification for a BGPPeer resource.
type BGPPeerSpecApplyConfiguration struct {
	// The node name identifying the Calico node instance that is targeted by this peer.
	// If this is not set, and no nodeSelector is specified, then this BGP peer selects all
	// nodes in the cluster.
	Node *string `json:"node,omitempty"`
	// Selector for the nodes that should have this peering.  When this is set, the Node
	// field must be empty.
	NodeSelector *string `json:"nodeSelector,omitempty"`
	// The IP address of the peer followed by an optional port number to peer with.
	// If port number is given, format should be `[<IPv6>]:port` or `<IPv4>:<port>` for IPv4.
	// If optional port number is not set, and this peer IP and ASNumber belongs to a calico/node
	// with ListenPort set in BGPConfiguration, then we use that port to peer.
	PeerIP *string `json:"peerIP,omitempty"`
	// The AS Number of the peer.
	ASNumber *numorstring.ASNumber `json:"asNumber,omitempty"`
	// The optional Local AS Number to use when peering with this remote peer.
	// If not specified, the AS Number defined in default BGPConfiguration will be used.
	LocalASNumber *numorstring.ASNumber `json:"localASNumber,omitempty"`
	// Selector for the remote nodes to peer with.  When this is set, the PeerIP and
	// ASNumber fields must be empty.  For each peering between the local node and
	// selected remote nodes, we configure an IPv4 peering if both ends have
	// NodeBGPSpec.IPv4Address specified, and an IPv6 peering if both ends have
	// NodeBGPSpec.IPv6Address specified.  The remote AS number comes from the remote
	// node's NodeBGPSpec.ASNumber, or the global default if that is not set.
	PeerSelector *string `json:"peerSelector,omitempty"`
	// Option to keep the original nexthop field when routes are sent to a BGP Peer.
	// Setting "true" configures the selected BGP Peers node to use the "next hop keep;"
	// instead of "next hop self;"(default) in the specific branch of the Node on "bird.cfg".
	// Note: that this field is deprecated. Users should use the NextHopMode field to control
	// the next hop attribute for a BGP peer.
	KeepOriginalNextHop *bool `json:"keepOriginalNextHop,omitempty"`
	// NextHopMode defines the method of calculating the next hop attribute for received routes.
	// This replaces and expands the deprecated KeepOriginalNextHop field.
	// Users should use this setting to control the next hop attribute for a BGP peer.
	// When this is set, the value of the KeepOriginalNextHop field is ignored.
	// if neither keepOriginalNextHop or nextHopMode is specified, BGP's default behaviour is used.
	// Set it to “Auto” to apply BGP’s default behaviour.
	// Set it to "Self" to configure "next hop self;" in "bird.cfg".
	// Set it to "Keep" to configure "next hop keep;" in "bird.cfg".
	NextHopMode *projectcalicov3.NextHopMode `json:"nextHopMode,omitempty"`
	// Optional BGP password for the peerings generated by this BGPPeer resource.
	Password *BGPPasswordApplyConfiguration `json:"password,omitempty"`
	// Specifies whether and how to configure a source address for the peerings generated by
	// this BGPPeer resource.  Default value "UseNodeIP" means to configure the node IP as the
	// source address.  "None" means not to configure a source address.
	SourceAddress *projectcalicov3.SourceAddress `json:"sourceAddress,omitempty"`
	// Time to allow for software restart.  When specified, this is configured as the graceful
	// restart timeout.  When not specified, the BIRD default of 120s is used.
	MaxRestartTime *v1.Duration `json:"maxRestartTime,omitempty"`
	// KeepaliveTime specifies the delay in seconds between sending consecutive Keepalive messages.
	// When specified, this configures the BGP keepalive timer for the peerings generated by this BGPPeer resource.
	// If not specified, BIRD uses its default keepalive time (one third of the hold time).
	KeepaliveTime *v1.Duration `json:"keepaliveTime,omitempty"`
	// Maximum number of local AS numbers that are allowed in the AS path for received routes.
	// This removes BGP loop prevention and should only be used if absolutely necessary.
	NumAllowedLocalASNumbers *int32 `json:"numAllowedLocalASNumbers,omitempty"`
	// TTLSecurity enables the generalized TTL security mechanism (GTSM) which protects against spoofed packets by
	// ignoring received packets with a smaller than expected TTL value. The provided value is the number of hops
	// (edges) between the peers.
	TTLSecurity *byte `json:"ttlSecurity,omitempty"`
	// Add an exact, i.e. /32, static route toward peer IP in order to prevent route flapping.
	// ReachableBy contains the address of the gateway which peer can be reached by.
	ReachableBy *string `json:"reachableBy,omitempty"`
	// The ordered set of BGPFilters applied on this BGP peer.
	Filters []string `json:"filters,omitempty"`
	// Selector for the local workload that the node should peer with. When this is set, the peerSelector and peerIP fields must be empty,
	// and the ASNumber must not be empty.
	LocalWorkloadSelector *string `json:"localWorkloadSelector,omitempty"`
	// ReversePeering, for peerings between Calico nodes controls whether
	// the reverse peering from nodes selected by peerSelector is generated
	// automatically. If set to Manual, a separate BGPPeer must be created
	// for the reverse peering. [Default: Auto]
	ReversePeering *projectcalicov3.ReversePeering `json:"reversePeering,omitempty"`
}

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

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

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

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

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

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

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

// WithKeepOriginalNextHop sets the KeepOriginalNextHop 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 KeepOriginalNextHop field is set to the value of the last call.
func (b *BGPPeerSpecApplyConfiguration) WithKeepOriginalNextHop(value bool) *BGPPeerSpecApplyConfiguration {
	b.KeepOriginalNextHop = &value
	return b
}

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

// WithPassword sets the Password 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 Password field is set to the value of the last call.
func (b *BGPPeerSpecApplyConfiguration) WithPassword(value *BGPPasswordApplyConfiguration) *BGPPeerSpecApplyConfiguration {
	b.Password = value
	return b
}

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

// WithMaxRestartTime sets the MaxRestartTime 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 MaxRestartTime field is set to the value of the last call.
func (b *BGPPeerSpecApplyConfiguration) WithMaxRestartTime(value v1.Duration) *BGPPeerSpecApplyConfiguration {
	b.MaxRestartTime = &value
	return b
}

// WithKeepaliveTime sets the KeepaliveTime 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 KeepaliveTime field is set to the value of the last call.
func (b *BGPPeerSpecApplyConfiguration) WithKeepaliveTime(value v1.Duration) *BGPPeerSpecApplyConfiguration {
	b.KeepaliveTime = &value
	return b
}

// WithNumAllowedLocalASNumbers sets the NumAllowedLocalASNumbers 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 NumAllowedLocalASNumbers field is set to the value of the last call.
func (b *BGPPeerSpecApplyConfiguration) WithNumAllowedLocalASNumbers(value int32) *BGPPeerSpecApplyConfiguration {
	b.NumAllowedLocalASNumbers = &value
	return b
}

// WithTTLSecurity sets the TTLSecurity 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 TTLSecurity field is set to the value of the last call.
func (b *BGPPeerSpecApplyConfiguration) WithTTLSecurity(value byte) *BGPPeerSpecApplyConfiguration {
	b.TTLSecurity = &value
	return b
}

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

// WithFilters adds the given value to the Filters 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 Filters field.
func (b *BGPPeerSpecApplyConfiguration) WithFilters(values ...string) *BGPPeerSpecApplyConfiguration {
	for i := range values {
		b.Filters = append(b.Filters, values[i])
	}
	return b
}

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

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