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

package sse_to_metadatav3

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

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

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

	var errors []error

	if m.GetResponseRules() == nil {
		err := SseToMetadataValidationError{
			field:  "ResponseRules",
			reason: "value is required",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = SseToMetadataValidationError{}

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

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

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

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

	var errors []error

	if m.GetContentParser() == nil {
		err := SseToMetadata_ProcessingRulesValidationError{
			field:  "ContentParser",
			reason: "value is required",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

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

		if wrapper.GetValue() > 10485760 {
			err := SseToMetadata_ProcessingRulesValidationError{
				field:  "MaxEventSize",
				reason: "value must be less than or equal to 10485760",
			}
			if !all {
				return err
			}
			errors = append(errors, err)
		}

	}

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = SseToMetadata_ProcessingRulesValidationError{}

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