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

package bandwidth_sharev3

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

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

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

	var errors []error

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

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

	if d := m.GetFillInterval(); d != nil {
		dur, err := d.AsDuration(), d.CheckValid()
		if err != nil {
			err = BandwidthShareValidationError{
				field:  "FillInterval",
				reason: "value is not a valid duration",
				cause:  err,
			}
			if !all {
				return err
			}
			errors = append(errors, err)
		} else {

			lte := time.Duration(1*time.Second + 0*time.Nanosecond)
			gte := time.Duration(0*time.Second + 20000000*time.Nanosecond)

			if dur < gte || dur > lte {
				err := BandwidthShareValidationError{
					field:  "FillInterval",
					reason: "value must be inside range [20ms, 1s]",
				}
				if !all {
					return err
				}
				errors = append(errors, err)
			}

		}
	}

	// no validation rules for EnableResponseTrailers

	if !_BandwidthShare_ResponseTrailerPrefix_Pattern.MatchString(m.GetResponseTrailerPrefix()) {
		err := BandwidthShareValidationError{
			field:  "ResponseTrailerPrefix",
			reason: "value does not match regex pattern \"^[^\\x00\\n\\r]*$\"",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

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

			// no validation rules for TenantConfigs[key]

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

		}
	}

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = BandwidthShareValidationError{}

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

var _BandwidthShare_ResponseTrailerPrefix_Pattern = regexp.MustCompile("^[^\x00\n\r]*$")

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

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

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

	var errors []error

	// no validation rules for Weight

	// no validation rules for IncludeStatsTag

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = BandwidthShare_TenantConfigValidationError{}

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

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

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

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

	var errors []error

	// no validation rules for BucketId

	if m.GetKbps() == nil {
		err := BandwidthShare_LimitValidationError{
			field:  "Kbps",
			reason: "value is required",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = BandwidthShare_LimitValidationError{}

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