//go:build !disable_pgv
// Code generated by protoc-gen-validate. DO NOT EDIT.
// source: envoy/extensions/outlier_detection_monitors/common/v3/error_types.proto

package commonv3

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 HttpErrors 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 *HttpErrors) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on HttpErrors 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 HttpErrorsMultiError, or
// nil if none found.
func (m *HttpErrors) ValidateAll() error {
	return m.validate(true)
}

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

	var errors []error

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

// Error satisfies the builtin error interface
func (e HttpErrorsValidationError) 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 %sHttpErrors.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = HttpErrorsValidationError{}

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

// Validate checks the field values on LocalOriginErrors 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 *LocalOriginErrors) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on LocalOriginErrors 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
// LocalOriginErrorsMultiError, or nil if none found.
func (m *LocalOriginErrors) ValidateAll() error {
	return m.validate(true)
}

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

	var errors []error

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

	return nil
}

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

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

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

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

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

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

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

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

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

// Error satisfies the builtin error interface
func (e LocalOriginErrorsValidationError) 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 %sLocalOriginErrors.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = LocalOriginErrorsValidationError{}

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

// Validate checks the field values on DatabaseErrors 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 *DatabaseErrors) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on DatabaseErrors 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 DatabaseErrorsMultiError,
// or nil if none found.
func (m *DatabaseErrors) ValidateAll() error {
	return m.validate(true)
}

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

	var errors []error

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

	return nil
}

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

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

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

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

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

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

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

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

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

// Error satisfies the builtin error interface
func (e DatabaseErrorsValidationError) 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 %sDatabaseErrors.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = DatabaseErrorsValidationError{}

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

// Validate checks the field values on ErrorBuckets 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 *ErrorBuckets) Validate() error {
	return m.validate(false)
}

// ValidateAll checks the field values on ErrorBuckets 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 ErrorBucketsMultiError, or
// nil if none found.
func (m *ErrorBuckets) ValidateAll() error {
	return m.validate(true)
}

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

	var errors []error

	for idx, item := range m.GetHttpErrors() {
		_, _ = idx, item

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

	}

	for idx, item := range m.GetLocalOriginErrors() {
		_, _ = idx, item

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

	}

	for idx, item := range m.GetDatabaseErrors() {
		_, _ = idx, item

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

	}

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

	return nil
}

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

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

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

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

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

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

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

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

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

// Error satisfies the builtin error interface
func (e ErrorBucketsValidationError) 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 %sErrorBuckets.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}

var _ error = ErrorBucketsValidationError{}

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