//go:build !disable_pgv
// Code generated by protoc-gen-validate. DO NOT EDIT.
// source: envoy/extensions/network/dns_resolver/hickory/v3/hickory_dns_resolver.proto

package hickoryv3

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

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

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

	var errors []error

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

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

	}

	if utf8.RuneCountInString(m.GetTlsServerName()) < 1 {
		err := DnsOverTlsConfigValidationError{
			field:  "TlsServerName",
			reason: "value length must be at least 1 runes",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = DnsOverTlsConfigValidationError{}

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

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

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

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

	var errors []error

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

		if utf8.RuneCountInString(item) < 1 {
			err := DnsOverHttpsConfigValidationError{
				field:  fmt.Sprintf("ServerUrls[%v]", idx),
				reason: "value length must be at least 1 runes",
			}
			if !all {
				return err
			}
			errors = append(errors, err)
		}

	}

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = DnsOverHttpsConfigValidationError{}

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

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

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

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

	var errors []error

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

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

	}

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

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

	// no validation rules for EnableDnssec

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

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

		if val := wrapper.GetValue(); val < 1 || val > 16 {
			err := HickoryDnsResolverConfigValidationError{
				field:  "NumResolverThreads",
				reason: "value must be inside range [1, 16]",
			}
			if !all {
				return err
			}
			errors = append(errors, err)
		}

	}

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

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

			gte := time.Duration(0*time.Second + 1000000*time.Nanosecond)

			if dur < gte {
				err := HickoryDnsResolverConfigValidationError{
					field:  "QueryTimeout",
					reason: "value must be greater than or equal to 1ms",
				}
				if !all {
					return err
				}
				errors = append(errors, err)
			}

		}
	}

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

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

	}

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = HickoryDnsResolverConfigValidationError{}

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