//go:build !disable_pgv
// Code generated by protoc-gen-validate. DO NOT EDIT.
// source: envoy/service/auth/v2/attribute_context.proto

package authv2

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

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

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

	var errors []error

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

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

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

	// no validation rules for ContextExtensions

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = AttributeContextValidationError{}

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

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

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

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

	var errors []error

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

	// no validation rules for Service

	// no validation rules for Labels

	// no validation rules for Principal

	// no validation rules for Certificate

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = AttributeContext_PeerValidationError{}

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

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

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

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

	var errors []error

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

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = AttributeContext_RequestValidationError{}

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

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

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

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

	var errors []error

	// no validation rules for Id

	// no validation rules for Method

	// no validation rules for Headers

	// no validation rules for Path

	// no validation rules for Host

	// no validation rules for Scheme

	// no validation rules for Query

	// no validation rules for Fragment

	// no validation rules for Size

	// no validation rules for Protocol

	// no validation rules for Body

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = AttributeContext_HttpRequestValidationError{}

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