// Code generated by protoc-gen-validate
// source: envoy/api/v2/discovery.proto
// DO NOT EDIT!!!

package v2

import (
	"bytes"
	"errors"
	"fmt"
	"net"
	"net/mail"
	"net/url"
	"regexp"
	"strings"
	"time"
	"unicode/utf8"

	"github.com/gogo/protobuf/types"
)

// 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)
	_ = types.DynamicAny{}
)

// Validate checks the field values on DiscoveryRequest with the rules defined
// in the proto definition for this message. If any rules are violated, an
// error is returned.
func (m *DiscoveryRequest) Validate() error {
	if m == nil {
		return nil
	}

	// no validation rules for VersionInfo

	if v, ok := interface{}(m.GetNode()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return DiscoveryRequestValidationError{
				Field:  "Node",
				Reason: "embedded message failed validation",
				Cause:  err,
			}
		}
	}

	// no validation rules for TypeUrl

	// no validation rules for ResponseNonce

	if v, ok := interface{}(m.GetErrorDetail()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return DiscoveryRequestValidationError{
				Field:  "ErrorDetail",
				Reason: "embedded message failed validation",
				Cause:  err,
			}
		}
	}

	return nil
}

// DiscoveryRequestValidationError is the validation error returned by
// DiscoveryRequest.Validate if the designated constraints aren't met.
type DiscoveryRequestValidationError struct {
	Field  string
	Reason string
	Cause  error
	Key    bool
}

// Error satisfies the builtin error interface
func (e DiscoveryRequestValidationError) 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 %sDiscoveryRequest.%s: %s%s",
		key,
		e.Field,
		e.Reason,
		cause)
}

var _ error = DiscoveryRequestValidationError{}

// Validate checks the field values on DiscoveryResponse with the rules defined
// in the proto definition for this message. If any rules are violated, an
// error is returned.
func (m *DiscoveryResponse) Validate() error {
	if m == nil {
		return nil
	}

	// no validation rules for VersionInfo

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

		if v, ok := interface{}(item).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return DiscoveryResponseValidationError{
					Field:  fmt.Sprintf("Resources[%v]", idx),
					Reason: "embedded message failed validation",
					Cause:  err,
				}
			}
		}

	}

	// no validation rules for Canary

	// no validation rules for TypeUrl

	// no validation rules for Nonce

	return nil
}

// DiscoveryResponseValidationError is the validation error returned by
// DiscoveryResponse.Validate if the designated constraints aren't met.
type DiscoveryResponseValidationError struct {
	Field  string
	Reason string
	Cause  error
	Key    bool
}

// Error satisfies the builtin error interface
func (e DiscoveryResponseValidationError) 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 %sDiscoveryResponse.%s: %s%s",
		key,
		e.Field,
		e.Reason,
		cause)
}

var _ error = DiscoveryResponseValidationError{}
