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

	certificatesv1 "k8s.io/api/certificates/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"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
	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 CertificateSigningRequest
	scheme.AddValidationFunc(
		(*certificatesv1.CertificateSigningRequest)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/", "/approval", "/status":
				return Validate_CertificateSigningRequest(
					ctx, op, nil, /* fldPath */
					obj.(*certificatesv1.CertificateSigningRequest),
					safe.Cast[*certificatesv1.CertificateSigningRequest](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	// type ClusterTrustBundle
	scheme.AddValidationFunc(
		(*certificatesv1.ClusterTrustBundle)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/":
				return Validate_ClusterTrustBundle(
					ctx, op, nil, /* fldPath */
					obj.(*certificatesv1.ClusterTrustBundle),
					safe.Cast[*certificatesv1.ClusterTrustBundle](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	// type PodCertificateRequest
	scheme.AddValidationFunc(
		(*certificatesv1.PodCertificateRequest)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/", "/status":
				return Validate_PodCertificateRequest(
					ctx, op, nil, /* fldPath */
					obj.(*certificatesv1.PodCertificateRequest),
					safe.Cast[*certificatesv1.PodCertificateRequest](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	return nil
}

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

	// field certificatesv1.CertificateSigningRequest.TypeMeta has no validation

	{ // field certificatesv1.CertificateSigningRequest.ObjectMeta
		fn := func(
			fldPath *field.Path,
			obj, oldObj *metav1.ObjectMeta,
			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, validation.Validate_ObjectMeta(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *certificatesv1.CertificateSigningRequest) *metav1.ObjectMeta {
				return &oldObj.ObjectMeta
			})
		errs = append(errs, fn(fldPath.Child("metadata"), &obj.ObjectMeta, oldVal, oldObj != nil)...)
	}

	// field certificatesv1.CertificateSigningRequest.Spec has no validation

	{ // field certificatesv1.CertificateSigningRequest.Status
		fn := func(
			fldPath *field.Path,
			obj, oldObj *certificatesv1.CertificateSigningRequestStatus,
			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_CertificateSigningRequestStatus(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *certificatesv1.CertificateSigningRequest) *certificatesv1.CertificateSigningRequestStatus {
				return &oldObj.Status
			})
		errs = append(errs, fn(fldPath.Child("status"), &obj.Status, oldVal, oldObj != nil)...)
	}

	return errs
}

var zeroOrOneOfMembershipFor_k8s_io_api_certificates_v1_CertificateSigningRequestStatus_conditions_ = validate.NewUnionMembership(validate.NewUnionMember("conditions[{\"type\": \"Approved\"}]"), validate.NewUnionMember("conditions[{\"type\": \"Denied\"}]"))

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

	{ // field certificatesv1.CertificateSigningRequestStatus.Conditions
		fn := func(
			fldPath *field.Path,
			obj, oldObj []certificatesv1.CertificateSigningRequestCondition,
			oldValueCorrelated bool) (errs field.ErrorList) {
			// Uniqueness validation is implemented via custom, handwritten validation
			// 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.OptionalSlice(ctx, op, fldPath, obj, oldObj).MarkBeta().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			if e := validate.ZeroOrOneOfUnion(ctx, op, fldPath, obj, oldObj, zeroOrOneOfMembershipFor_k8s_io_api_certificates_v1_CertificateSigningRequestStatus_conditions_,
				func(list []certificatesv1.CertificateSigningRequestCondition) bool {
					for i := range list {
						if list[i].Type == "Approved" {
							return true
						}
					}
					return false
				},
				func(list []certificatesv1.CertificateSigningRequestCondition) bool {
					for i := range list {
						if list[i].Type == "Denied" {
							return true
						}
					}
					return false
				}).MarkBeta(); len(e) != 0 {
				errs = append(errs, e...)
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *certificatesv1.CertificateSigningRequestStatus) []certificatesv1.CertificateSigningRequestCondition {
				return oldObj.Conditions
			})
		errs = append(errs, fn(fldPath.Child("conditions"), obj.Conditions, oldVal, oldObj != nil)...)
	}

	// field certificatesv1.CertificateSigningRequestStatus.Certificate has no validation
	return errs
}

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

	// field certificatesv1.ClusterTrustBundle.TypeMeta has no validation

	{ // field certificatesv1.ClusterTrustBundle.ObjectMeta
		fn := func(
			fldPath *field.Path,
			obj, oldObj *metav1.ObjectMeta,
			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, validation.Validate_ObjectMeta(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *certificatesv1.ClusterTrustBundle) *metav1.ObjectMeta {
				return &oldObj.ObjectMeta
			})
		errs = append(errs, fn(fldPath.Child("metadata"), &obj.ObjectMeta, oldVal, oldObj != nil)...)
	}

	{ // field certificatesv1.ClusterTrustBundle.Spec
		fn := func(
			fldPath *field.Path,
			obj, oldObj *certificatesv1.ClusterTrustBundleSpec,
			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 the type's validation function
			errs = append(errs, Validate_ClusterTrustBundleSpec(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *certificatesv1.ClusterTrustBundle) *certificatesv1.ClusterTrustBundleSpec {
				return &oldObj.Spec
			})
		errs = append(errs, fn(fldPath.Child("spec"), &obj.Spec, oldVal, oldObj != nil)...)
	}

	return errs
}

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

	{ // field certificatesv1.ClusterTrustBundleSpec.SignerName
		fn := func(
			fldPath *field.Path,
			obj, oldObj *string,
			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.OptionalValue(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if e := validate.Immutable(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *certificatesv1.ClusterTrustBundleSpec) *string {
				return &oldObj.SignerName
			})
		errs = append(errs, fn(fldPath.Child("signerName"), &obj.SignerName, oldVal, oldObj != nil)...)
	}

	// field certificatesv1.ClusterTrustBundleSpec.TrustBundle has no validation
	return errs
}

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

	// field certificatesv1.PodCertificateRequest.TypeMeta has no validation

	{ // field certificatesv1.PodCertificateRequest.ObjectMeta
		fn := func(
			fldPath *field.Path,
			obj, oldObj *metav1.ObjectMeta,
			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, validation.Validate_ObjectMeta(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *certificatesv1.PodCertificateRequest) *metav1.ObjectMeta {
				return &oldObj.ObjectMeta
			})
		errs = append(errs, fn(fldPath.Child("metadata"), &obj.ObjectMeta, oldVal, oldObj != nil)...)
	}

	// field certificatesv1.PodCertificateRequest.Spec has no validation

	{ // field certificatesv1.PodCertificateRequest.Status
		fn := func(
			fldPath *field.Path,
			obj, oldObj *certificatesv1.PodCertificateRequestStatus,
			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_PodCertificateRequestStatus(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *certificatesv1.PodCertificateRequest) *certificatesv1.PodCertificateRequestStatus {
				return &oldObj.Status
			})
		errs = append(errs, fn(fldPath.Child("status"), &obj.Status, oldVal, oldObj != nil)...)
	}

	return errs
}

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

	{ // field certificatesv1.PodCertificateRequestStatus.Conditions
		fn := func(
			fldPath *field.Path,
			obj, oldObj []metav1.Condition,
			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.OptionalSlice(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			// lists with map semantics require unique keys
			if e := validate.ValSliceUnique(ctx, op, fldPath, obj, oldObj,
				func(a *metav1.Condition, b *metav1.Condition) bool { return a.Type == b.Type }).MarkAlpha(); len(e) != 0 {
				errs = append(errs, e...)
			}
			// iterate the list and call the type's validation function
			if e := validate.EachValSliceVal(ctx, op, fldPath, obj, oldObj,
				func(a *metav1.Condition, b *metav1.Condition) bool { return a.Type == b.Type }, validate.SemanticDeepEqual, validation.Validate_Condition); len(e) != 0 {
				errs = append(errs, e...)
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *certificatesv1.PodCertificateRequestStatus) []metav1.Condition {
				return oldObj.Conditions
			})
		errs = append(errs, fn(fldPath.Child("conditions"), obj.Conditions, oldVal, oldObj != nil)...)
	}

	// field certificatesv1.PodCertificateRequestStatus.CertificateChain has no validation
	// field certificatesv1.PodCertificateRequestStatus.NotBefore has no validation
	// field certificatesv1.PodCertificateRequestStatus.BeginRefreshAt has no validation
	// field certificatesv1.PodCertificateRequestStatus.NotAfter has no validation
	return errs
}
