//go:build !ignore_autogenerated
// +build !ignore_autogenerated

/*
Copyright The Kubernetes 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 validation-gen. DO NOT EDIT.

package v1

import (
	context "context"
	fmt "fmt"

	flowcontrolv1 "k8s.io/api/flowcontrol/v1"
	equality "k8s.io/apimachinery/pkg/api/equality"
	operation "k8s.io/apimachinery/pkg/api/operation"
	safe "k8s.io/apimachinery/pkg/api/safe"
	validate "k8s.io/apimachinery/pkg/api/validate"
	runtime "k8s.io/apimachinery/pkg/runtime"
	field "k8s.io/apimachinery/pkg/util/validation/field"
)

func init() { localSchemeBuilder.Register(RegisterValidations) }

// RegisterValidations adds validation functions to the given scheme.
// Public to allow building arbitrary schemes.
func RegisterValidations(scheme *runtime.Scheme) error {
	// type PriorityLevelConfiguration
	scheme.AddValidationFunc((*flowcontrolv1.PriorityLevelConfiguration)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
		switch op.Request.SubresourcePath() {
		case "/":
			return Validate_PriorityLevelConfiguration(ctx, op, nil /* fldPath */, obj.(*flowcontrolv1.PriorityLevelConfiguration), safe.Cast[*flowcontrolv1.PriorityLevelConfiguration](oldObj))
		}
		return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath()))}
	})
	return nil
}

// Validate_LimitResponse validates an instance of LimitResponse according
// to declarative validation rules in the API schema.
func Validate_LimitResponse(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.LimitResponse) (errs field.ErrorList) {
	errs = append(errs, validate.Discriminated(ctx, op, fldPath, obj, oldObj, "queuing", func(obj *flowcontrolv1.LimitResponse) *flowcontrolv1.QueuingConfiguration { return obj.Queuing }, func(obj *flowcontrolv1.LimitResponse) flowcontrolv1.LimitResponseType { return obj.Type }, validate.DirectEqualPtr, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.QueuingConfiguration) field.ErrorList {
		errs := field.ErrorList{}
		errs = append(errs, validate.ForbiddenPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha()...)
		return errs
	}, []validate.DiscriminatedRule[*flowcontrolv1.QueuingConfiguration, flowcontrolv1.LimitResponseType]{
		{
			Value: "Queue", Validation: func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.QueuingConfiguration) field.ErrorList {
				errs := field.ErrorList{}
				earlyReturn := false
				if e := validate.RequiredPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
					errs = append(errs, e...)
					earlyReturn = true
				}
				if earlyReturn {
					return errs
				}
				return errs
			}},
		{
			Value: "Reject", Validation: func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.QueuingConfiguration) field.ErrorList {
				errs := field.ErrorList{}
				earlyReturn := false
				if e := validate.ForbiddenPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
					errs = append(errs, e...)
					earlyReturn = true
				}
				if e := validate.OptionalPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
					earlyReturn = true
				}
				if earlyReturn {
					return errs
				}
				return errs
			}},
	})...)

	// field flowcontrolv1.LimitResponse.Type
	errs = append(errs,
		func(fldPath *field.Path, obj, oldObj *flowcontrolv1.LimitResponseType, oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update && (obj == oldObj || (obj != nil && oldObj != nil && *obj == *oldObj)) {
				return nil
			}
			// call field-attached validations
			earlyReturn := false
			if e := validate.RequiredValue(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}(fldPath.Child("type"), &obj.Type, safe.Field(oldObj, func(oldObj *flowcontrolv1.LimitResponse) *flowcontrolv1.LimitResponseType { return &oldObj.Type }), oldObj != nil)...)

	// field flowcontrolv1.LimitResponse.Queuing
	errs = append(errs,
		func(fldPath *field.Path, obj, oldObj *flowcontrolv1.QueuingConfiguration, oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update && (obj == oldObj || (obj != nil && oldObj != nil && *obj == *oldObj)) {
				return nil
			}
			// call field-attached validations
			earlyReturn := false
			if e := validate.OptionalPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}(fldPath.Child("queuing"), obj.Queuing, safe.Field(oldObj, func(oldObj *flowcontrolv1.LimitResponse) *flowcontrolv1.QueuingConfiguration { return oldObj.Queuing }), oldObj != nil)...)

	return errs
}

// Validate_LimitedPriorityLevelConfiguration validates an instance of LimitedPriorityLevelConfiguration according
// to declarative validation rules in the API schema.
func Validate_LimitedPriorityLevelConfiguration(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.LimitedPriorityLevelConfiguration) (errs field.ErrorList) {
	// field flowcontrolv1.LimitedPriorityLevelConfiguration.NominalConcurrencyShares has no validation

	// field flowcontrolv1.LimitedPriorityLevelConfiguration.LimitResponse
	errs = append(errs,
		func(fldPath *field.Path, obj, oldObj *flowcontrolv1.LimitResponse, oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update && equality.Semantic.DeepEqual(obj, oldObj) {
				return nil
			}
			// call the type's validation function
			errs = append(errs, Validate_LimitResponse(ctx, op, fldPath, obj, oldObj)...)
			return
		}(fldPath.Child("limitResponse"), &obj.LimitResponse, safe.Field(oldObj, func(oldObj *flowcontrolv1.LimitedPriorityLevelConfiguration) *flowcontrolv1.LimitResponse {
			return &oldObj.LimitResponse
		}), oldObj != nil)...)

	// field flowcontrolv1.LimitedPriorityLevelConfiguration.LendablePercent has no validation
	// field flowcontrolv1.LimitedPriorityLevelConfiguration.BorrowingLimitPercent has no validation
	return errs
}

// Validate_PriorityLevelConfiguration validates an instance of PriorityLevelConfiguration according
// to declarative validation rules in the API schema.
func Validate_PriorityLevelConfiguration(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.PriorityLevelConfiguration) (errs field.ErrorList) {
	// field flowcontrolv1.PriorityLevelConfiguration.TypeMeta has no validation
	// field flowcontrolv1.PriorityLevelConfiguration.ObjectMeta has no validation

	// field flowcontrolv1.PriorityLevelConfiguration.Spec
	errs = append(errs,
		func(fldPath *field.Path, obj, oldObj *flowcontrolv1.PriorityLevelConfigurationSpec, oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update && equality.Semantic.DeepEqual(obj, oldObj) {
				return nil
			}
			// call the type's validation function
			errs = append(errs, Validate_PriorityLevelConfigurationSpec(ctx, op, fldPath, obj, oldObj)...)
			return
		}(fldPath.Child("spec"), &obj.Spec, safe.Field(oldObj, func(oldObj *flowcontrolv1.PriorityLevelConfiguration) *flowcontrolv1.PriorityLevelConfigurationSpec {
			return &oldObj.Spec
		}), oldObj != nil)...)

	// field flowcontrolv1.PriorityLevelConfiguration.Status has no validation
	return errs
}

// Validate_PriorityLevelConfigurationSpec validates an instance of PriorityLevelConfigurationSpec according
// to declarative validation rules in the API schema.
func Validate_PriorityLevelConfigurationSpec(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.PriorityLevelConfigurationSpec) (errs field.ErrorList) {
	errs = append(errs, validate.Discriminated(ctx, op, fldPath, obj, oldObj, "exempt", func(obj *flowcontrolv1.PriorityLevelConfigurationSpec) *flowcontrolv1.ExemptPriorityLevelConfiguration {
		return obj.Exempt
	}, func(obj *flowcontrolv1.PriorityLevelConfigurationSpec) flowcontrolv1.PriorityLevelEnablement {
		return obj.Type
	}, validate.SemanticDeepEqual, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.ExemptPriorityLevelConfiguration) field.ErrorList {
		errs := field.ErrorList{}
		errs = append(errs, validate.ForbiddenPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha()...)
		return errs
	}, []validate.DiscriminatedRule[*flowcontrolv1.ExemptPriorityLevelConfiguration, flowcontrolv1.PriorityLevelEnablement]{
		{
			Value: "Exempt", Validation: func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.ExemptPriorityLevelConfiguration) field.ErrorList {
				errs := field.ErrorList{}
				earlyReturn := false
				if e := validate.OptionalPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
					earlyReturn = true
				}
				if earlyReturn {
					return errs
				}
				return errs
			}},
		{
			Value: "Limited", Validation: func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.ExemptPriorityLevelConfiguration) field.ErrorList {
				errs := field.ErrorList{}
				earlyReturn := false
				if e := validate.ForbiddenPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
					errs = append(errs, e...)
					earlyReturn = true
				}
				if e := validate.OptionalPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
					earlyReturn = true
				}
				if earlyReturn {
					return errs
				}
				return errs
			}},
	})...)
	errs = append(errs, validate.Discriminated(ctx, op, fldPath, obj, oldObj, "limited", func(obj *flowcontrolv1.PriorityLevelConfigurationSpec) *flowcontrolv1.LimitedPriorityLevelConfiguration {
		return obj.Limited
	}, func(obj *flowcontrolv1.PriorityLevelConfigurationSpec) flowcontrolv1.PriorityLevelEnablement {
		return obj.Type
	}, validate.SemanticDeepEqual, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.LimitedPriorityLevelConfiguration) field.ErrorList {
		errs := field.ErrorList{}
		errs = append(errs, validate.ForbiddenPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha()...)
		return errs
	}, []validate.DiscriminatedRule[*flowcontrolv1.LimitedPriorityLevelConfiguration, flowcontrolv1.PriorityLevelEnablement]{
		{
			Value: "Exempt", Validation: func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.LimitedPriorityLevelConfiguration) field.ErrorList {
				errs := field.ErrorList{}
				earlyReturn := false
				if e := validate.ForbiddenPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
					errs = append(errs, e...)
					earlyReturn = true
				}
				if e := validate.OptionalPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
					earlyReturn = true
				}
				if earlyReturn {
					return errs
				}
				return errs
			}},
		{
			Value: "Limited", Validation: func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *flowcontrolv1.LimitedPriorityLevelConfiguration) field.ErrorList {
				errs := field.ErrorList{}
				earlyReturn := false
				if e := validate.RequiredPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
					errs = append(errs, e...)
					earlyReturn = true
				}
				if earlyReturn {
					return errs
				}
				return errs
			}},
	})...)

	// field flowcontrolv1.PriorityLevelConfigurationSpec.Type
	errs = append(errs,
		func(fldPath *field.Path, obj, oldObj *flowcontrolv1.PriorityLevelEnablement, oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update && (obj == oldObj || (obj != nil && oldObj != nil && *obj == *oldObj)) {
				return nil
			}
			// call field-attached validations
			earlyReturn := false
			if e := validate.RequiredValue(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}(fldPath.Child("type"), &obj.Type, safe.Field(oldObj, func(oldObj *flowcontrolv1.PriorityLevelConfigurationSpec) *flowcontrolv1.PriorityLevelEnablement {
			return &oldObj.Type
		}), oldObj != nil)...)

	// field flowcontrolv1.PriorityLevelConfigurationSpec.Limited
	errs = append(errs,
		func(fldPath *field.Path, obj, oldObj *flowcontrolv1.LimitedPriorityLevelConfiguration, oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update && equality.Semantic.DeepEqual(obj, oldObj) {
				return nil
			}
			// call field-attached validations
			earlyReturn := false
			if e := validate.OptionalPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			// call the type's validation function
			errs = append(errs, Validate_LimitedPriorityLevelConfiguration(ctx, op, fldPath, obj, oldObj)...)
			return
		}(fldPath.Child("limited"), obj.Limited, safe.Field(oldObj, func(oldObj *flowcontrolv1.PriorityLevelConfigurationSpec) *flowcontrolv1.LimitedPriorityLevelConfiguration {
			return oldObj.Limited
		}), oldObj != nil)...)

	// field flowcontrolv1.PriorityLevelConfigurationSpec.Exempt
	errs = append(errs,
		func(fldPath *field.Path, obj, oldObj *flowcontrolv1.ExemptPriorityLevelConfiguration, oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update && equality.Semantic.DeepEqual(obj, oldObj) {
				return nil
			}
			// call field-attached validations
			earlyReturn := false
			if e := validate.OptionalPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}(fldPath.Child("exempt"), obj.Exempt, safe.Field(oldObj, func(oldObj *flowcontrolv1.PriorityLevelConfigurationSpec) *flowcontrolv1.ExemptPriorityLevelConfiguration {
			return oldObj.Exempt
		}), oldObj != nil)...)

	return errs
}
