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

	authorizationv1 "k8s.io/api/authorization/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 LocalSubjectAccessReview
	scheme.AddValidationFunc(
		(*authorizationv1.LocalSubjectAccessReview)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/", "/status":
				return Validate_LocalSubjectAccessReview(
					ctx, op, nil, /* fldPath */
					obj.(*authorizationv1.LocalSubjectAccessReview),
					safe.Cast[*authorizationv1.LocalSubjectAccessReview](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	// type SelfSubjectAccessReview
	scheme.AddValidationFunc(
		(*authorizationv1.SelfSubjectAccessReview)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/", "/status":
				return Validate_SelfSubjectAccessReview(
					ctx, op, nil, /* fldPath */
					obj.(*authorizationv1.SelfSubjectAccessReview),
					safe.Cast[*authorizationv1.SelfSubjectAccessReview](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	// type SubjectAccessReview
	scheme.AddValidationFunc(
		(*authorizationv1.SubjectAccessReview)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/", "/status":
				return Validate_SubjectAccessReview(
					ctx, op, nil, /* fldPath */
					obj.(*authorizationv1.SubjectAccessReview),
					safe.Cast[*authorizationv1.SubjectAccessReview](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	return nil
}

// Validate_LocalSubjectAccessReview validates an instance of LocalSubjectAccessReview according
// to declarative validation rules in the API schema.
func Validate_LocalSubjectAccessReview(
	ctx context.Context, op operation.Operation, fldPath *field.Path,
	obj, oldObj *authorizationv1.LocalSubjectAccessReview) (errs field.ErrorList) {

	// field authorizationv1.LocalSubjectAccessReview.TypeMeta has no validation
	// field authorizationv1.LocalSubjectAccessReview.ObjectMeta has no validation

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

	// field authorizationv1.LocalSubjectAccessReview.Status has no validation
	return errs
}

// Validate_SelfSubjectAccessReview validates an instance of SelfSubjectAccessReview according
// to declarative validation rules in the API schema.
func Validate_SelfSubjectAccessReview(
	ctx context.Context, op operation.Operation, fldPath *field.Path,
	obj, oldObj *authorizationv1.SelfSubjectAccessReview) (errs field.ErrorList) {

	// field authorizationv1.SelfSubjectAccessReview.TypeMeta has no validation
	// field authorizationv1.SelfSubjectAccessReview.ObjectMeta has no validation

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

	// field authorizationv1.SelfSubjectAccessReview.Status has no validation
	return errs
}

var unionMembershipFor_k8s_io_api_authorization_v1_SelfSubjectAccessReviewSpec_ = validate.NewUnionMembership(validate.NewUnionMember("resourceAttributes"), validate.NewUnionMember("nonResourceAttributes"))

// Validate_SelfSubjectAccessReviewSpec validates an instance of SelfSubjectAccessReviewSpec according
// to declarative validation rules in the API schema.
func Validate_SelfSubjectAccessReviewSpec(
	ctx context.Context, op operation.Operation, fldPath *field.Path,
	obj, oldObj *authorizationv1.SelfSubjectAccessReviewSpec) (errs field.ErrorList) {

	if e := validate.Union(ctx, op, fldPath, obj, oldObj, unionMembershipFor_k8s_io_api_authorization_v1_SelfSubjectAccessReviewSpec_,
		func(obj *authorizationv1.SelfSubjectAccessReviewSpec) bool {
			if obj == nil {
				return false
			}
			return obj.ResourceAttributes != nil
		},
		func(obj *authorizationv1.SelfSubjectAccessReviewSpec) bool {
			if obj == nil {
				return false
			}
			return obj.NonResourceAttributes != nil
		}).MarkAlpha(); len(e) != 0 {
		errs = append(errs, e...)
	}

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

	{ // field authorizationv1.SelfSubjectAccessReviewSpec.NonResourceAttributes
		fn := func(
			fldPath *field.Path,
			obj, oldObj *authorizationv1.NonResourceAttributes,
			oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update {
				if 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().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *authorizationv1.SelfSubjectAccessReviewSpec) *authorizationv1.NonResourceAttributes {
				return oldObj.NonResourceAttributes
			})
		errs = append(errs, fn(fldPath.Child("nonResourceAttributes"), obj.NonResourceAttributes, oldVal, oldObj != nil)...)
	}

	return errs
}

// Validate_SubjectAccessReview validates an instance of SubjectAccessReview according
// to declarative validation rules in the API schema.
func Validate_SubjectAccessReview(
	ctx context.Context, op operation.Operation, fldPath *field.Path,
	obj, oldObj *authorizationv1.SubjectAccessReview) (errs field.ErrorList) {

	// field authorizationv1.SubjectAccessReview.TypeMeta has no validation
	// field authorizationv1.SubjectAccessReview.ObjectMeta has no validation

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

	// field authorizationv1.SubjectAccessReview.Status has no validation
	return errs
}

var unionMembershipFor_k8s_io_api_authorization_v1_SubjectAccessReviewSpec_ = validate.NewUnionMembership(validate.NewUnionMember("resourceAttributes"), validate.NewUnionMember("nonResourceAttributes"))

// Validate_SubjectAccessReviewSpec validates an instance of SubjectAccessReviewSpec according
// to declarative validation rules in the API schema.
func Validate_SubjectAccessReviewSpec(
	ctx context.Context, op operation.Operation, fldPath *field.Path,
	obj, oldObj *authorizationv1.SubjectAccessReviewSpec) (errs field.ErrorList) {

	if e := validate.Union(ctx, op, fldPath, obj, oldObj, unionMembershipFor_k8s_io_api_authorization_v1_SubjectAccessReviewSpec_,
		func(obj *authorizationv1.SubjectAccessReviewSpec) bool {
			if obj == nil {
				return false
			}
			return obj.ResourceAttributes != nil
		},
		func(obj *authorizationv1.SubjectAccessReviewSpec) bool {
			if obj == nil {
				return false
			}
			return obj.NonResourceAttributes != nil
		}).MarkAlpha(); len(e) != 0 {
		errs = append(errs, e...)
	}

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

	{ // field authorizationv1.SubjectAccessReviewSpec.NonResourceAttributes
		fn := func(
			fldPath *field.Path,
			obj, oldObj *authorizationv1.NonResourceAttributes,
			oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update {
				if 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().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *authorizationv1.SubjectAccessReviewSpec) *authorizationv1.NonResourceAttributes {
				return oldObj.NonResourceAttributes
			})
		errs = append(errs, fn(fldPath.Child("nonResourceAttributes"), obj.NonResourceAttributes, oldVal, oldObj != nil)...)
	}

	// field authorizationv1.SubjectAccessReviewSpec.User has no validation
	// field authorizationv1.SubjectAccessReviewSpec.Groups has no validation
	// field authorizationv1.SubjectAccessReviewSpec.Extra has no validation
	// field authorizationv1.SubjectAccessReviewSpec.UID has no validation
	return errs
}
