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

package proto_message_extractionv3

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

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

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

	var errors []error

	// no validation rules for Mode

	{
		sorted_keys := make([]string, len(m.GetExtractionByMethod()))
		i := 0
		for key := range m.GetExtractionByMethod() {
			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.GetExtractionByMethod()[key]
			_ = val

			// no validation rules for ExtractionByMethod[key]

			if all {
				switch v := interface{}(val).(type) {
				case interface{ ValidateAll() error }:
					if err := v.ValidateAll(); err != nil {
						errors = append(errors, ProtoMessageExtractionConfigValidationError{
							field:  fmt.Sprintf("ExtractionByMethod[%v]", key),
							reason: "embedded message failed validation",
							cause:  err,
						})
					}
				case interface{ Validate() error }:
					if err := v.Validate(); err != nil {
						errors = append(errors, ProtoMessageExtractionConfigValidationError{
							field:  fmt.Sprintf("ExtractionByMethod[%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 ProtoMessageExtractionConfigValidationError{
						field:  fmt.Sprintf("ExtractionByMethod[%v]", key),
						reason: "embedded message failed validation",
						cause:  err,
					}
				}
			}

		}
	}

	switch v := m.DescriptorSet.(type) {
	case *ProtoMessageExtractionConfig_DataSource:
		if v == nil {
			err := ProtoMessageExtractionConfigValidationError{
				field:  "DescriptorSet",
				reason: "oneof value cannot be a typed-nil",
			}
			if !all {
				return err
			}
			errors = append(errors, err)
		}

		if all {
			switch v := interface{}(m.GetDataSource()).(type) {
			case interface{ ValidateAll() error }:
				if err := v.ValidateAll(); err != nil {
					errors = append(errors, ProtoMessageExtractionConfigValidationError{
						field:  "DataSource",
						reason: "embedded message failed validation",
						cause:  err,
					})
				}
			case interface{ Validate() error }:
				if err := v.Validate(); err != nil {
					errors = append(errors, ProtoMessageExtractionConfigValidationError{
						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 ProtoMessageExtractionConfigValidationError{
					field:  "DataSource",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}

	case *ProtoMessageExtractionConfig_ProtoDescriptorTypedMetadata:
		if v == nil {
			err := ProtoMessageExtractionConfigValidationError{
				field:  "DescriptorSet",
				reason: "oneof value cannot be a typed-nil",
			}
			if !all {
				return err
			}
			errors = append(errors, err)
		}
		// no validation rules for ProtoDescriptorTypedMetadata
	default:
		_ = v // ensures v is used
	}

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

	return nil
}

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

// Error returns a concatenation of all the error messages it wraps.
func (m ProtoMessageExtractionConfigMultiError) 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 ProtoMessageExtractionConfigMultiError) AllErrors() []error { return m }

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

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

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

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

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

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

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

var _ error = ProtoMessageExtractionConfigValidationError{}

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

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

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

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

	var errors []error

	// no validation rules for RequestExtractionByField

	// no validation rules for ResponseExtractionByField

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

	return nil
}

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

// Error returns a concatenation of all the error messages it wraps.
func (m MethodExtractionMultiError) 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 MethodExtractionMultiError) AllErrors() []error { return m }

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

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

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

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

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

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

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

var _ error = MethodExtractionValidationError{}

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