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

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

package v3

import (
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// IPAMBlockSpecApplyConfiguration represents a declarative configuration of the IPAMBlockSpec type for use
// with apply.
//
// IPAMBlockSpec contains the specification for an IPAMBlock resource.
type IPAMBlockSpecApplyConfiguration struct {
	// The block's CIDR.
	CIDR *string `json:"cidr,omitempty"`
	// Affinity of the block, if this block has one. If set, it will be of the form
	// "host:<hostname>" or "virtual:<hostname>". If not set, this block is not affine to a host.
	Affinity *string `json:"affinity,omitempty"`
	// Time at which affinity was claimed.
	AffinityClaimTime *v1.Time `json:"affinityClaimTime,omitempty"`
	// Array of allocations in-use within this block. nil entries mean the allocation is free.
	// For non-nil entries at index i, the index is the ordinal of the allocation within this block
	// and the value is the index of the associated attributes in the Attributes array.
	Allocations []*int `json:"allocations,omitempty"`
	// Unallocated is an ordered list of allocations which are free in the block.
	Unallocated []int `json:"unallocated,omitempty"`
	// Attributes is an array of arbitrary metadata associated with allocations in the block. To find
	// attributes for a given allocation, use the value of the allocation's entry in the Allocations array
	// as the index of the element in this array.
	Attributes []AllocationAttributeApplyConfiguration `json:"attributes,omitempty"`
	// We store a sequence number that is updated each time the block is written.
	// Each allocation will also store the sequence number of the block at the time of its creation.
	// When releasing an IP, passing the sequence number associated with the allocation allows us
	// to protect against a race condition and ensure the IP hasn't been released and re-allocated
	// since the release request.
	SequenceNumber *uint64 `json:"sequenceNumber,omitempty"`
	// Map of allocated ordinal within the block to sequence number of the block at
	// the time of allocation. Kubernetes does not allow numerical keys for maps, so
	// the key is cast to a string.
	SequenceNumberForAllocation map[string]uint64 `json:"sequenceNumberForAllocation,omitempty"`
	// Deleted is an internal boolean used to workaround a limitation in the Kubernetes API whereby
	// deletion will not return a conflict error if the block has been updated. It should not be set manually.
	Deleted *bool `json:"deleted,omitempty"`
	// StrictAffinity on the IPAMBlock is deprecated and no longer used by the code. Use IPAMConfig StrictAffinity instead.
	DeprecatedStrictAffinity *bool `json:"strictAffinity,omitempty"`
}

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

// 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 *IPAMBlockSpecApplyConfiguration) WithCIDR(value string) *IPAMBlockSpecApplyConfiguration {
	b.CIDR = &value
	return b
}

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

// WithAffinityClaimTime sets the AffinityClaimTime 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 AffinityClaimTime field is set to the value of the last call.
func (b *IPAMBlockSpecApplyConfiguration) WithAffinityClaimTime(value v1.Time) *IPAMBlockSpecApplyConfiguration {
	b.AffinityClaimTime = &value
	return b
}

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

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

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

// WithSequenceNumber sets the SequenceNumber 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 SequenceNumber field is set to the value of the last call.
func (b *IPAMBlockSpecApplyConfiguration) WithSequenceNumber(value uint64) *IPAMBlockSpecApplyConfiguration {
	b.SequenceNumber = &value
	return b
}

// WithSequenceNumberForAllocation puts the entries into the SequenceNumberForAllocation field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, the entries provided by each call will be put on the SequenceNumberForAllocation field,
// overwriting an existing map entries in SequenceNumberForAllocation field with the same key.
func (b *IPAMBlockSpecApplyConfiguration) WithSequenceNumberForAllocation(entries map[string]uint64) *IPAMBlockSpecApplyConfiguration {
	if b.SequenceNumberForAllocation == nil && len(entries) > 0 {
		b.SequenceNumberForAllocation = make(map[string]uint64, len(entries))
	}
	for k, v := range entries {
		b.SequenceNumberForAllocation[k] = v
	}
	return b
}

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

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