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

package transformv3

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

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

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

	var errors []error

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

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

	// no validation rules for ClearClusterCache

	// no validation rules for ClearRouteCache

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = TransformConfigValidationError{}

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

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

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

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

	var errors []error

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

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

	}

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = TransformationValidationError{}

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

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

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

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

	var errors []error

	if m.GetBodyFormat() == nil {
		err := BodyTransformationValidationError{
			field:  "BodyFormat",
			reason: "value is required",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

	// no validation rules for Action

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = BodyTransformationValidationError{}

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