// Code generated by protoc-gen-validate. DO NOT EDIT.
// source: envoy/extensions/load_balancing_policies/least_request/v3/least_request.proto

package least_requestv3

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

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

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

	var errors []error

	if wrapper := m.GetChoiceCount(); wrapper != nil {

		if wrapper.GetValue() < 2 {
			err := LeastRequestValidationError{
				field:  "ChoiceCount",
				reason: "value must be greater than or equal to 2",
			}
			if !all {
				return err
			}
			errors = append(errors, err)
		}

	}

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

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

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

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = LeastRequestValidationError{}

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