//go:build !disable_pgv
// Code generated by protoc-gen-validate. DO NOT EDIT.
// source: envoy/extensions/filters/http/proto_api_scrubber/v3/config.proto

package proto_api_scrubberv3

import (
	"bytes"
	"errors"
	"fmt"
	"net"
	"net/mail"
	"net/url"
	"regexp"
	"sort"
	"strings"
	"time"
	"unicode/utf8"

	"google.golang.org/protobuf/types/known/anypb"
)

// ensure the imports are used
var (
	_ = bytes.MinRead
	_ = errors.New("")
	_ = fmt.Print
	_ = utf8.UTFMax
	_ = (*regexp.Regexp)(nil)
	_ = (*strings.Reader)(nil)
	_ = net.IPv4len
	_ = time.Duration(0)
	_ = (*url.URL)(nil)
	_ = (*mail.Address)(nil)
	_ = anypb.Any{}
	_ = sort.Sort
)

// Validate checks the field values on ProtoApiScrubberConfig with the rules
// defined in the proto definition for this message. If any rules are
// violated, the first error encountered is returned, or nil if there are no violations.
func (m *ProtoApiScrubberConfig) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on ProtoApiScrubberConfig with the rules
// defined in the proto definition for this message. If any rules are
// violated, the result is a list of violation errors wrapped in
// ProtoApiScrubberConfigMultiError, or nil if none found.
func (m *ProtoApiScrubberConfig) ValidateAll() error {
	return m.validate(true)
}

func (m *ProtoApiScrubberConfig) validate(all bool) error {
	if m == nil {
		return nil
	}

	var errors []error

	if all {
		switch v := interface{}(m.GetDescriptorSet()).(type) {
		case interface{ ValidateAll() error }:
			if err := v.ValidateAll(); err != nil {
				errors = append(errors, ProtoApiScrubberConfigValidationError{
					field:  "DescriptorSet",
					reason: "embedded message failed validation",
					cause:  err,
				})
			}
		case interface{ Validate() error }:
			if err := v.Validate(); err != nil {
				errors = append(errors, ProtoApiScrubberConfigValidationError{
					field:  "DescriptorSet",
					reason: "embedded message failed validation",
					cause:  err,
				})
			}
		}
	} else if v, ok := interface{}(m.GetDescriptorSet()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return ProtoApiScrubberConfigValidationError{
				field:  "DescriptorSet",
				reason: "embedded message failed validation",
				cause:  err,
			}
		}
	}

	if all {
		switch v := interface{}(m.GetRestrictions()).(type) {
		case interface{ ValidateAll() error }:
			if err := v.ValidateAll(); err != nil {
				errors = append(errors, ProtoApiScrubberConfigValidationError{
					field:  "Restrictions",
					reason: "embedded message failed validation",
					cause:  err,
				})
			}
		case interface{ Validate() error }:
			if err := v.Validate(); err != nil {
				errors = append(errors, ProtoApiScrubberConfigValidationError{
					field:  "Restrictions",
					reason: "embedded message failed validation",
					cause:  err,
				})
			}
		}
	} else if v, ok := interface{}(m.GetRestrictions()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return ProtoApiScrubberConfigValidationError{
				field:  "Restrictions",
				reason: "embedded message failed validation",
				cause:  err,
			}
		}
	}

	// no validation rules for FilteringMode

	if len(errors) > 0 {
		return ProtoApiScrubberConfigMultiError(errors)
	}

	return nil
}

// ProtoApiScrubberConfigMultiError is an error wrapping multiple validation
// errors returned by ProtoApiScrubberConfig.ValidateAll() if the designated
// constraints aren't met.
type ProtoApiScrubberConfigMultiError []error

// Error returns a concatenation of all the error messages it wraps.
func (m ProtoApiScrubberConfigMultiError) Error() string {
	var msgs []string
	for _, err := range m {
		msgs = append(msgs, err.Error())
	}
	return strings.Join(msgs, "; ")
}

// AllErrors returns a list of validation violation errors.
func (m ProtoApiScrubberConfigMultiError) AllErrors() []error { return m }

// ProtoApiScrubberConfigValidationError is the validation error returned by
// ProtoApiScrubberConfig.Validate if the designated constraints aren't met.
type ProtoApiScrubberConfigValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}

// Field function returns field value.
func (e ProtoApiScrubberConfigValidationError) Field() string { return e.field }

// Reason function returns reason value.
func (e ProtoApiScrubberConfigValidationError) Reason() string { return e.reason }

// Cause function returns cause value.
func (e ProtoApiScrubberConfigValidationError) Cause() error { return e.cause }

// Key function returns key value.
func (e ProtoApiScrubberConfigValidationError) Key() bool { return e.key }

// ErrorName returns error name.
func (e ProtoApiScrubberConfigValidationError) ErrorName() string {
	return "ProtoApiScrubberConfigValidationError"
}

// Error satisfies the builtin error interface
func (e ProtoApiScrubberConfigValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}

	key := ""
	if e.key {
		key = "key for "
	}

	return fmt.Sprintf(
		"invalid %sProtoApiScrubberConfig.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = ProtoApiScrubberConfigValidationError{}

var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = ProtoApiScrubberConfigValidationError{}

// Validate checks the field values on DescriptorSet with the rules defined in
// the proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *DescriptorSet) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on DescriptorSet with the rules defined
// in the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in DescriptorSetMultiError, or
// nil if none found.
func (m *DescriptorSet) ValidateAll() error {
	return m.validate(true)
}

func (m *DescriptorSet) validate(all bool) error {
	if m == nil {
		return nil
	}

	var errors []error

	if all {
		switch v := interface{}(m.GetDataSource()).(type) {
		case interface{ ValidateAll() error }:
			if err := v.ValidateAll(); err != nil {
				errors = append(errors, DescriptorSetValidationError{
					field:  "DataSource",
					reason: "embedded message failed validation",
					cause:  err,
				})
			}
		case interface{ Validate() error }:
			if err := v.Validate(); err != nil {
				errors = append(errors, DescriptorSetValidationError{
					field:  "DataSource",
					reason: "embedded message failed validation",
					cause:  err,
				})
			}
		}
	} else if v, ok := interface{}(m.GetDataSource()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return DescriptorSetValidationError{
				field:  "DataSource",
				reason: "embedded message failed validation",
				cause:  err,
			}
		}
	}

	if len(errors) > 0 {
		return DescriptorSetMultiError(errors)
	}

	return nil
}

// DescriptorSetMultiError is an error wrapping multiple validation errors
// returned by DescriptorSet.ValidateAll() if the designated constraints
// aren't met.
type DescriptorSetMultiError []error

// Error returns a concatenation of all the error messages it wraps.
func (m DescriptorSetMultiError) Error() string {
	var msgs []string
	for _, err := range m {
		msgs = append(msgs, err.Error())
	}
	return strings.Join(msgs, "; ")
}

// AllErrors returns a list of validation violation errors.
func (m DescriptorSetMultiError) AllErrors() []error { return m }

// DescriptorSetValidationError is the validation error returned by
// DescriptorSet.Validate if the designated constraints aren't met.
type DescriptorSetValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}

// Field function returns field value.
func (e DescriptorSetValidationError) Field() string { return e.field }

// Reason function returns reason value.
func (e DescriptorSetValidationError) Reason() string { return e.reason }

// Cause function returns cause value.
func (e DescriptorSetValidationError) Cause() error { return e.cause }

// Key function returns key value.
func (e DescriptorSetValidationError) Key() bool { return e.key }

// ErrorName returns error name.
func (e DescriptorSetValidationError) ErrorName() string { return "DescriptorSetValidationError" }

// Error satisfies the builtin error interface
func (e DescriptorSetValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}

	key := ""
	if e.key {
		key = "key for "
	}

	return fmt.Sprintf(
		"invalid %sDescriptorSet.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = DescriptorSetValidationError{}

var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = DescriptorSetValidationError{}

// Validate checks the field values on Restrictions with the rules defined in
// the proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *Restrictions) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on Restrictions with the rules defined
// in the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in RestrictionsMultiError, or
// nil if none found.
func (m *Restrictions) ValidateAll() error {
	return m.validate(true)
}

func (m *Restrictions) validate(all bool) error {
	if m == nil {
		return nil
	}

	var errors []error

	{
		sorted_keys := make([]string, len(m.GetMethodRestrictions()))
		i := 0
		for key := range m.GetMethodRestrictions() {
			sorted_keys[i] = key
			i++
		}
		sort.Slice(sorted_keys, func(i, j int) bool { return sorted_keys[i] < sorted_keys[j] })
		for _, key := range sorted_keys {
			val := m.GetMethodRestrictions()[key]
			_ = val

			// no validation rules for MethodRestrictions[key]

			if all {
				switch v := interface{}(val).(type) {
				case interface{ ValidateAll() error }:
					if err := v.ValidateAll(); err != nil {
						errors = append(errors, RestrictionsValidationError{
							field:  fmt.Sprintf("MethodRestrictions[%v]", key),
							reason: "embedded message failed validation",
							cause:  err,
						})
					}
				case interface{ Validate() error }:
					if err := v.Validate(); err != nil {
						errors = append(errors, RestrictionsValidationError{
							field:  fmt.Sprintf("MethodRestrictions[%v]", key),
							reason: "embedded message failed validation",
							cause:  err,
						})
					}
				}
			} else if v, ok := interface{}(val).(interface{ Validate() error }); ok {
				if err := v.Validate(); err != nil {
					return RestrictionsValidationError{
						field:  fmt.Sprintf("MethodRestrictions[%v]", key),
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}

		}
	}

	if len(errors) > 0 {
		return RestrictionsMultiError(errors)
	}

	return nil
}

// RestrictionsMultiError is an error wrapping multiple validation errors
// returned by Restrictions.ValidateAll() if the designated constraints aren't met.
type RestrictionsMultiError []error

// Error returns a concatenation of all the error messages it wraps.
func (m RestrictionsMultiError) Error() string {
	var msgs []string
	for _, err := range m {
		msgs = append(msgs, err.Error())
	}
	return strings.Join(msgs, "; ")
}

// AllErrors returns a list of validation violation errors.
func (m RestrictionsMultiError) AllErrors() []error { return m }

// RestrictionsValidationError is the validation error returned by
// Restrictions.Validate if the designated constraints aren't met.
type RestrictionsValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}

// Field function returns field value.
func (e RestrictionsValidationError) Field() string { return e.field }

// Reason function returns reason value.
func (e RestrictionsValidationError) Reason() string { return e.reason }

// Cause function returns cause value.
func (e RestrictionsValidationError) Cause() error { return e.cause }

// Key function returns key value.
func (e RestrictionsValidationError) Key() bool { return e.key }

// ErrorName returns error name.
func (e RestrictionsValidationError) ErrorName() string { return "RestrictionsValidationError" }

// Error satisfies the builtin error interface
func (e RestrictionsValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}

	key := ""
	if e.key {
		key = "key for "
	}

	return fmt.Sprintf(
		"invalid %sRestrictions.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = RestrictionsValidationError{}

var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = RestrictionsValidationError{}

// Validate checks the field values on MethodRestrictions with the rules
// defined in the proto definition for this message. If any rules are
// violated, the first error encountered is returned, or nil if there are no violations.
func (m *MethodRestrictions) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on MethodRestrictions with the rules
// defined in the proto definition for this message. If any rules are
// violated, the result is a list of violation errors wrapped in
// MethodRestrictionsMultiError, or nil if none found.
func (m *MethodRestrictions) ValidateAll() error {
	return m.validate(true)
}

func (m *MethodRestrictions) validate(all bool) error {
	if m == nil {
		return nil
	}

	var errors []error

	{
		sorted_keys := make([]string, len(m.GetRequestFieldRestrictions()))
		i := 0
		for key := range m.GetRequestFieldRestrictions() {
			sorted_keys[i] = key
			i++
		}
		sort.Slice(sorted_keys, func(i, j int) bool { return sorted_keys[i] < sorted_keys[j] })
		for _, key := range sorted_keys {
			val := m.GetRequestFieldRestrictions()[key]
			_ = val

			// no validation rules for RequestFieldRestrictions[key]

			if all {
				switch v := interface{}(val).(type) {
				case interface{ ValidateAll() error }:
					if err := v.ValidateAll(); err != nil {
						errors = append(errors, MethodRestrictionsValidationError{
							field:  fmt.Sprintf("RequestFieldRestrictions[%v]", key),
							reason: "embedded message failed validation",
							cause:  err,
						})
					}
				case interface{ Validate() error }:
					if err := v.Validate(); err != nil {
						errors = append(errors, MethodRestrictionsValidationError{
							field:  fmt.Sprintf("RequestFieldRestrictions[%v]", key),
							reason: "embedded message failed validation",
							cause:  err,
						})
					}
				}
			} else if v, ok := interface{}(val).(interface{ Validate() error }); ok {
				if err := v.Validate(); err != nil {
					return MethodRestrictionsValidationError{
						field:  fmt.Sprintf("RequestFieldRestrictions[%v]", key),
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}

		}
	}

	{
		sorted_keys := make([]string, len(m.GetResponseFieldRestrictions()))
		i := 0
		for key := range m.GetResponseFieldRestrictions() {
			sorted_keys[i] = key
			i++
		}
		sort.Slice(sorted_keys, func(i, j int) bool { return sorted_keys[i] < sorted_keys[j] })
		for _, key := range sorted_keys {
			val := m.GetResponseFieldRestrictions()[key]
			_ = val

			// no validation rules for ResponseFieldRestrictions[key]

			if all {
				switch v := interface{}(val).(type) {
				case interface{ ValidateAll() error }:
					if err := v.ValidateAll(); err != nil {
						errors = append(errors, MethodRestrictionsValidationError{
							field:  fmt.Sprintf("ResponseFieldRestrictions[%v]", key),
							reason: "embedded message failed validation",
							cause:  err,
						})
					}
				case interface{ Validate() error }:
					if err := v.Validate(); err != nil {
						errors = append(errors, MethodRestrictionsValidationError{
							field:  fmt.Sprintf("ResponseFieldRestrictions[%v]", key),
							reason: "embedded message failed validation",
							cause:  err,
						})
					}
				}
			} else if v, ok := interface{}(val).(interface{ Validate() error }); ok {
				if err := v.Validate(); err != nil {
					return MethodRestrictionsValidationError{
						field:  fmt.Sprintf("ResponseFieldRestrictions[%v]", key),
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}

		}
	}

	if len(errors) > 0 {
		return MethodRestrictionsMultiError(errors)
	}

	return nil
}

// MethodRestrictionsMultiError is an error wrapping multiple validation errors
// returned by MethodRestrictions.ValidateAll() if the designated constraints
// aren't met.
type MethodRestrictionsMultiError []error

// Error returns a concatenation of all the error messages it wraps.
func (m MethodRestrictionsMultiError) Error() string {
	var msgs []string
	for _, err := range m {
		msgs = append(msgs, err.Error())
	}
	return strings.Join(msgs, "; ")
}

// AllErrors returns a list of validation violation errors.
func (m MethodRestrictionsMultiError) AllErrors() []error { return m }

// MethodRestrictionsValidationError is the validation error returned by
// MethodRestrictions.Validate if the designated constraints aren't met.
type MethodRestrictionsValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}

// Field function returns field value.
func (e MethodRestrictionsValidationError) Field() string { return e.field }

// Reason function returns reason value.
func (e MethodRestrictionsValidationError) Reason() string { return e.reason }

// Cause function returns cause value.
func (e MethodRestrictionsValidationError) Cause() error { return e.cause }

// Key function returns key value.
func (e MethodRestrictionsValidationError) Key() bool { return e.key }

// ErrorName returns error name.
func (e MethodRestrictionsValidationError) ErrorName() string {
	return "MethodRestrictionsValidationError"
}

// Error satisfies the builtin error interface
func (e MethodRestrictionsValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}

	key := ""
	if e.key {
		key = "key for "
	}

	return fmt.Sprintf(
		"invalid %sMethodRestrictions.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = MethodRestrictionsValidationError{}

var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = MethodRestrictionsValidationError{}

// Validate checks the field values on RestrictionConfig with the rules defined
// in the proto definition for this message. If any rules are violated, the
// first error encountered is returned, or nil if there are no violations.
func (m *RestrictionConfig) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on RestrictionConfig with the rules
// defined in the proto definition for this message. If any rules are
// violated, the result is a list of violation errors wrapped in
// RestrictionConfigMultiError, or nil if none found.
func (m *RestrictionConfig) ValidateAll() error {
	return m.validate(true)
}

func (m *RestrictionConfig) validate(all bool) error {
	if m == nil {
		return nil
	}

	var errors []error

	if all {
		switch v := interface{}(m.GetMatcher()).(type) {
		case interface{ ValidateAll() error }:
			if err := v.ValidateAll(); err != nil {
				errors = append(errors, RestrictionConfigValidationError{
					field:  "Matcher",
					reason: "embedded message failed validation",
					cause:  err,
				})
			}
		case interface{ Validate() error }:
			if err := v.Validate(); err != nil {
				errors = append(errors, RestrictionConfigValidationError{
					field:  "Matcher",
					reason: "embedded message failed validation",
					cause:  err,
				})
			}
		}
	} else if v, ok := interface{}(m.GetMatcher()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return RestrictionConfigValidationError{
				field:  "Matcher",
				reason: "embedded message failed validation",
				cause:  err,
			}
		}
	}

	if len(errors) > 0 {
		return RestrictionConfigMultiError(errors)
	}

	return nil
}

// RestrictionConfigMultiError is an error wrapping multiple validation errors
// returned by RestrictionConfig.ValidateAll() if the designated constraints
// aren't met.
type RestrictionConfigMultiError []error

// Error returns a concatenation of all the error messages it wraps.
func (m RestrictionConfigMultiError) Error() string {
	var msgs []string
	for _, err := range m {
		msgs = append(msgs, err.Error())
	}
	return strings.Join(msgs, "; ")
}

// AllErrors returns a list of validation violation errors.
func (m RestrictionConfigMultiError) AllErrors() []error { return m }

// RestrictionConfigValidationError is the validation error returned by
// RestrictionConfig.Validate if the designated constraints aren't met.
type RestrictionConfigValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}

// Field function returns field value.
func (e RestrictionConfigValidationError) Field() string { return e.field }

// Reason function returns reason value.
func (e RestrictionConfigValidationError) Reason() string { return e.reason }

// Cause function returns cause value.
func (e RestrictionConfigValidationError) Cause() error { return e.cause }

// Key function returns key value.
func (e RestrictionConfigValidationError) Key() bool { return e.key }

// ErrorName returns error name.
func (e RestrictionConfigValidationError) ErrorName() string {
	return "RestrictionConfigValidationError"
}

// Error satisfies the builtin error interface
func (e RestrictionConfigValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}

	key := ""
	if e.key {
		key = "key for "
	}

	return fmt.Sprintf(
		"invalid %sRestrictionConfig.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = RestrictionConfigValidationError{}

var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = RestrictionConfigValidationError{}
