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

package filter_chainv3

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

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

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

	var errors []error

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = FilterChainConfigValidationError{}

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

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

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

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

	var errors []error

	if m.GetFilterChain() == nil {
		err := FilterChainConfigPerRouteValidationError{
			field:  "FilterChain",
			reason: "value is required",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = FilterChainConfigPerRouteValidationError{}

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

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

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

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

	var errors []error

	if len(m.GetFilters()) < 1 {
		err := FilterChainValidationError{
			field:  "Filters",
			reason: "value must contain at least 1 item(s)",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

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

	}

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = FilterChainValidationError{}

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