/*
Copyright The Volcano 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 (
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	batchv1alpha1 "volcano.sh/apis/pkg/client/applyconfiguration/batch/v1alpha1"
)

// PatchApplyConfiguration represents a declarative configuration of the Patch type for use
// with apply.
type PatchApplyConfiguration struct {
	*batchv1alpha1.JobSpecApplyConfiguration `json:"jobSpec,omitempty"`
}

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

// WithSchedulerName sets the SchedulerName 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 SchedulerName field is set to the value of the last call.
func (b *PatchApplyConfiguration) WithSchedulerName(value string) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	b.JobSpecApplyConfiguration.SchedulerName = &value
	return b
}

// WithMinAvailable sets the MinAvailable 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 MinAvailable field is set to the value of the last call.
func (b *PatchApplyConfiguration) WithMinAvailable(value int32) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	b.JobSpecApplyConfiguration.MinAvailable = &value
	return b
}

// WithVolumes adds the given value to the Volumes 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 Volumes field.
func (b *PatchApplyConfiguration) WithVolumes(values ...*batchv1alpha1.VolumeSpecApplyConfiguration) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithVolumes")
		}
		b.JobSpecApplyConfiguration.Volumes = append(b.JobSpecApplyConfiguration.Volumes, *values[i])
	}
	return b
}

// WithTasks adds the given value to the Tasks 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 Tasks field.
func (b *PatchApplyConfiguration) WithTasks(values ...*batchv1alpha1.TaskSpecApplyConfiguration) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithTasks")
		}
		b.JobSpecApplyConfiguration.Tasks = append(b.JobSpecApplyConfiguration.Tasks, *values[i])
	}
	return b
}

// WithPolicies adds the given value to the Policies 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 Policies field.
func (b *PatchApplyConfiguration) WithPolicies(values ...*batchv1alpha1.LifecyclePolicyApplyConfiguration) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	for i := range values {
		if values[i] == nil {
			panic("nil value passed to WithPolicies")
		}
		b.JobSpecApplyConfiguration.Policies = append(b.JobSpecApplyConfiguration.Policies, *values[i])
	}
	return b
}

// WithPlugins puts the entries into the Plugins 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 Plugins field,
// overwriting an existing map entries in Plugins field with the same key.
func (b *PatchApplyConfiguration) WithPlugins(entries map[string][]string) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	if b.JobSpecApplyConfiguration.Plugins == nil && len(entries) > 0 {
		b.JobSpecApplyConfiguration.Plugins = make(map[string][]string, len(entries))
	}
	for k, v := range entries {
		b.JobSpecApplyConfiguration.Plugins[k] = v
	}
	return b
}

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

// WithQueue sets the Queue 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 Queue field is set to the value of the last call.
func (b *PatchApplyConfiguration) WithQueue(value string) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	b.JobSpecApplyConfiguration.Queue = &value
	return b
}

// WithMaxRetry sets the MaxRetry 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 MaxRetry field is set to the value of the last call.
func (b *PatchApplyConfiguration) WithMaxRetry(value int32) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	b.JobSpecApplyConfiguration.MaxRetry = &value
	return b
}

// WithTTLSecondsAfterFinished sets the TTLSecondsAfterFinished 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 TTLSecondsAfterFinished field is set to the value of the last call.
func (b *PatchApplyConfiguration) WithTTLSecondsAfterFinished(value int32) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	b.JobSpecApplyConfiguration.TTLSecondsAfterFinished = &value
	return b
}

// WithPriorityClassName sets the PriorityClassName 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 PriorityClassName field is set to the value of the last call.
func (b *PatchApplyConfiguration) WithPriorityClassName(value string) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	b.JobSpecApplyConfiguration.PriorityClassName = &value
	return b
}

// WithMinSuccess sets the MinSuccess 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 MinSuccess field is set to the value of the last call.
func (b *PatchApplyConfiguration) WithMinSuccess(value int32) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	b.JobSpecApplyConfiguration.MinSuccess = &value
	return b
}

// WithNetworkTopology sets the NetworkTopology 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 NetworkTopology field is set to the value of the last call.
func (b *PatchApplyConfiguration) WithNetworkTopology(value *batchv1alpha1.NetworkTopologySpecApplyConfiguration) *PatchApplyConfiguration {
	b.ensureJobSpecApplyConfigurationExists()
	b.JobSpecApplyConfiguration.NetworkTopology = value
	return b
}

func (b *PatchApplyConfiguration) ensureJobSpecApplyConfigurationExists() {
	if b.JobSpecApplyConfiguration == nil {
		b.JobSpecApplyConfiguration = &batchv1alpha1.JobSpecApplyConfiguration{}
	}
}
