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

package file_serverv3

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

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

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

	var errors []error

	if m.GetManagerConfig() == nil {
		err := FileServerConfigValidationError{
			field:  "ManagerConfig",
			reason: "value is required",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

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

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

	}

	{
		sorted_keys := make([]string, len(m.GetContentTypes()))
		i := 0
		for key := range m.GetContentTypes() {
			sorted_keys[i] = key
			i++
		}
		sort.Slice(sorted_keys, func(i, j int) bool { return sorted_keys[i] < sorted_keys[j] })
		for _, key := range sorted_keys {
			val := m.GetContentTypes()[key]
			_ = val

			if !_FileServerConfig_ContentTypes_Pattern.MatchString(key) {
				err := FileServerConfigValidationError{
					field:  fmt.Sprintf("ContentTypes[%v]", key),
					reason: "value does not match regex pattern \"^[a-z0-9_\\\\-]*$\"",
				}
				if !all {
					return err
				}
				errors = append(errors, err)
			}

			// no validation rules for ContentTypes[key]
		}
	}

	// no validation rules for DefaultContentType

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

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

	}

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = FileServerConfigValidationError{}

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

var _FileServerConfig_ContentTypes_Pattern = regexp.MustCompile("^[a-z0-9_\\-]*$")

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

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

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

	var errors []error

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

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = FileServerConfig_PathMappingValidationError{}

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

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

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

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

	var errors []error

	if !_FileServerConfig_DirectoryBehavior_DefaultFile_Pattern.MatchString(m.GetDefaultFile()) {
		err := FileServerConfig_DirectoryBehaviorValidationError{
			field:  "DefaultFile",
			reason: "value does not match regex pattern \"^[^/]*$\"",
		}
		if !all {
			return err
		}
		errors = append(errors, err)
	}

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = FileServerConfig_DirectoryBehaviorValidationError{}

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

var _FileServerConfig_DirectoryBehavior_DefaultFile_Pattern = regexp.MustCompile("^[^/]*$")

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

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

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

	var errors []error

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

	return nil
}

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

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

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

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

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

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

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

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

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

var _ error = FileServerConfig_DirectoryBehavior_ListValidationError{}

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