func (e RoleDefValidationError) 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 %sRoleDef.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
Error satisfies the builtin error interface
package policyv1
import (
	"bytes"
	"errors"
	"fmt"
	"net"
	"net/mail"
	"net/url"
	"regexp"
	"strings"
	"time"
	"unicode/utf8"
	"google.golang.org/protobuf/types/known/anypb"
	effectv1 "github.com/cerbos/cerbos/api/genpb/cerbos/effect/v1"
)
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{}
	_ = effectv1.Effect(0)
	_ = effectv1.Effect(0)
)
func (m *Policy) Validate() error {
	if m == nil {
		return nil
	}
	if m.GetApiVersion() != "api.cerbos.dev/v1" {
		return PolicyValidationError{
			field:  "ApiVersion",
			reason: "value must equal api.cerbos.dev/v1",
		}
	}
	if v, ok := interface{}(m.GetMetadata()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return PolicyValidationError{
				field:  "Metadata",
				reason: "embedded message failed validation",
				cause:  err,
			}
		}
	}
	switch m.PolicyType.(type) {
	case *Policy_ResourcePolicy:
		if v, ok := interface{}(m.GetResourcePolicy()).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return PolicyValidationError{
					field:  "ResourcePolicy",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	case *Policy_PrincipalPolicy:
		if v, ok := interface{}(m.GetPrincipalPolicy()).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return PolicyValidationError{
					field:  "PrincipalPolicy",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	case *Policy_DerivedRoles:
		if v, ok := interface{}(m.GetDerivedRoles()).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return PolicyValidationError{
					field:  "DerivedRoles",
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	default:
		return PolicyValidationError{
			field:  "PolicyType",
			reason: "value is required",
		}
	}
	return nil
}
type PolicyValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e PolicyValidationError) Field() string { return e.field }
func (e PolicyValidationError) Reason() string { return e.reason }
func (e PolicyValidationError) Cause() error { return e.cause }
func (e PolicyValidationError) Key() bool { return e.key }
func (e PolicyValidationError) ErrorName() string { return "PolicyValidationError" }
func (e PolicyValidationError) 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 %sPolicy.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
var _ error = PolicyValidationError{}
var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = PolicyValidationError{}
func (m *Metadata) Validate() error {
	if m == nil {
		return nil
	}
	return nil
}
type MetadataValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e MetadataValidationError) Field() string { return e.field }
func (e MetadataValidationError) Reason() string { return e.reason }
func (e MetadataValidationError) Cause() error { return e.cause }
func (e MetadataValidationError) Key() bool { return e.key }
func (e MetadataValidationError) ErrorName() string { return "MetadataValidationError" }
func (e MetadataValidationError) 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 %sMetadata.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
var _ error = MetadataValidationError{}
var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = MetadataValidationError{}
func (m *ResourcePolicy) Validate() error {
	if m == nil {
		return nil
	}
	if utf8.RuneCountInString(m.GetResource()) < 1 {
		return ResourcePolicyValidationError{
			field:  "Resource",
			reason: "value length must be at least 1 runes",
		}
	}
	if !_ResourcePolicy_Resource_Pattern.MatchString(m.GetResource()) {
		return ResourcePolicyValidationError{
			field:  "Resource",
			reason: "value does not match regex pattern \"^[[:alpha:]][[:word:]\\\\@\\\\.\\\\-/]*(\\\\:[[:alpha:]][[:word:]\\\\@\\\\.\\\\-/]*)*$\"",
		}
	}
	if !_ResourcePolicy_Version_Pattern.MatchString(m.GetVersion()) {
		return ResourcePolicyValidationError{
			field:  "Version",
			reason: "value does not match regex pattern \"^[[:word:]]+$\"",
		}
	}
	_ResourcePolicy_ImportDerivedRoles_Unique := make(map[string]struct{}, len(m.GetImportDerivedRoles()))
	for idx, item := range m.GetImportDerivedRoles() {
		_, _ = idx, item
		if _, exists := _ResourcePolicy_ImportDerivedRoles_Unique[item]; exists {
			return ResourcePolicyValidationError{
				field:  fmt.Sprintf("ImportDerivedRoles[%v]", idx),
				reason: "repeated value must contain unique items",
			}
		} else {
			_ResourcePolicy_ImportDerivedRoles_Unique[item] = struct{}{}
		}
		if !_ResourcePolicy_ImportDerivedRoles_Pattern.MatchString(item) {
			return ResourcePolicyValidationError{
				field:  fmt.Sprintf("ImportDerivedRoles[%v]", idx),
				reason: "value does not match regex pattern \"^[[:word:]\\\\-\\\\.]+$\"",
			}
		}
	}
	if len(m.GetRules()) < 1 {
		return ResourcePolicyValidationError{
			field:  "Rules",
			reason: "value must contain at least 1 item(s)",
		}
	}
	for idx, item := range m.GetRules() {
		_, _ = idx, item
		if v, ok := interface{}(item).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return ResourcePolicyValidationError{
					field:  fmt.Sprintf("Rules[%v]", idx),
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}
	if !_ResourcePolicy_Scope_Pattern.MatchString(m.GetScope()) {
		return ResourcePolicyValidationError{
			field:  "Scope",
			reason: "value does not match regex pattern \"^([[:alpha:]][[:word:]\\\\-]+(\\\\.[[:alpha:]][[:word:]\\\\-]*)*)*$\"",
		}
	}
	return nil
}
type ResourcePolicyValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e ResourcePolicyValidationError) Field() string { return e.field }
func (e ResourcePolicyValidationError) Reason() string { return e.reason }
func (e ResourcePolicyValidationError) Cause() error { return e.cause }
func (e ResourcePolicyValidationError) Key() bool { return e.key }
func (e ResourcePolicyValidationError) ErrorName() string { return "ResourcePolicyValidationError" }
func (e ResourcePolicyValidationError) 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 %sResourcePolicy.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
var _ error = ResourcePolicyValidationError{}
var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = ResourcePolicyValidationError{}
var _ResourcePolicy_Resource_Pattern = regexp.MustCompile("^[[:alpha:]][[:word:]\\@\\.\\-/]*(\\:[[:alpha:]][[:word:]\\@\\.\\-/]*)*$")
var _ResourcePolicy_Version_Pattern = regexp.MustCompile("^[[:word:]]+$")
var _ResourcePolicy_ImportDerivedRoles_Pattern = regexp.MustCompile("^[[:word:]\\-\\.]+$")
var _ResourcePolicy_Scope_Pattern = regexp.MustCompile("^([[:alpha:]][[:word:]\\-]+(\\.[[:alpha:]][[:word:]\\-]*)*)*$")
func (m *ResourceRule) Validate() error {
	if m == nil {
		return nil
	}
	_ResourceRule_Actions_Unique := make(map[string]struct{}, len(m.GetActions()))
	for idx, item := range m.GetActions() {
		_, _ = idx, item
		if _, exists := _ResourceRule_Actions_Unique[item]; exists {
			return ResourceRuleValidationError{
				field:  fmt.Sprintf("Actions[%v]", idx),
				reason: "repeated value must contain unique items",
			}
		} else {
			_ResourceRule_Actions_Unique[item] = struct{}{}
		}
		if utf8.RuneCountInString(item) < 1 {
			return ResourceRuleValidationError{
				field:  fmt.Sprintf("Actions[%v]", idx),
				reason: "value length must be at least 1 runes",
			}
		}
	}
	_ResourceRule_DerivedRoles_Unique := make(map[string]struct{}, len(m.GetDerivedRoles()))
	for idx, item := range m.GetDerivedRoles() {
		_, _ = idx, item
		if _, exists := _ResourceRule_DerivedRoles_Unique[item]; exists {
			return ResourceRuleValidationError{
				field:  fmt.Sprintf("DerivedRoles[%v]", idx),
				reason: "repeated value must contain unique items",
			}
		} else {
			_ResourceRule_DerivedRoles_Unique[item] = struct{}{}
		}
		if !_ResourceRule_DerivedRoles_Pattern.MatchString(item) {
			return ResourceRuleValidationError{
				field:  fmt.Sprintf("DerivedRoles[%v]", idx),
				reason: "value does not match regex pattern \"^[[:word:]\\\\-\\\\.]+$\"",
			}
		}
	}
	_ResourceRule_Roles_Unique := make(map[string]struct{}, len(m.GetRoles()))
	for idx, item := range m.GetRoles() {
		_, _ = idx, item
		if _, exists := _ResourceRule_Roles_Unique[item]; exists {
			return ResourceRuleValidationError{
				field:  fmt.Sprintf("Roles[%v]", idx),
				reason: "repeated value must contain unique items",
			}
		} else {
			_ResourceRule_Roles_Unique[item] = struct{}{}
		}
		if !_ResourceRule_Roles_Pattern.MatchString(item) {
			return ResourceRuleValidationError{
				field:  fmt.Sprintf("Roles[%v]", idx),
				reason: "value does not match regex pattern \"^[[:word:]\\\\-\\\\.]+$\"",
			}
		}
	}
	if v, ok := interface{}(m.GetCondition()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return ResourceRuleValidationError{
				field:  "Condition",
				reason: "embedded message failed validation",
				cause:  err,
			}
		}
	}
	if _, ok := _ResourceRule_Effect_InLookup[m.GetEffect()]; !ok {
		return ResourceRuleValidationError{
			field:  "Effect",
			reason: "value must be in list [1 2]",
		}
	}
	if !_ResourceRule_Name_Pattern.MatchString(m.GetName()) {
		return ResourceRuleValidationError{
			field:  "Name",
			reason: "value does not match regex pattern \"^([[:alpha:]][[:word:]\\\\@\\\\.\\\\-]*)*$\"",
		}
	}
	return nil
}
type ResourceRuleValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e ResourceRuleValidationError) Field() string { return e.field }
func (e ResourceRuleValidationError) Reason() string { return e.reason }
func (e ResourceRuleValidationError) Cause() error { return e.cause }
func (e ResourceRuleValidationError) Key() bool { return e.key }
func (e ResourceRuleValidationError) ErrorName() string { return "ResourceRuleValidationError" }
func (e ResourceRuleValidationError) 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 %sResourceRule.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
var _ error = ResourceRuleValidationError{}
var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = ResourceRuleValidationError{}
var _ResourceRule_DerivedRoles_Pattern = regexp.MustCompile("^[[:word:]\\-\\.]+$")
var _ResourceRule_Roles_Pattern = regexp.MustCompile("^[[:word:]\\-\\.]+$")
var _ResourceRule_Effect_InLookup = map[effectv1.Effect]struct{}{
	1: {},
	2: {},
}
var _ResourceRule_Name_Pattern = regexp.MustCompile("^([[:alpha:]][[:word:]\\@\\.\\-]*)*$")
func (m *PrincipalPolicy) Validate() error {
	if m == nil {
		return nil
	}
	if utf8.RuneCountInString(m.GetPrincipal()) < 1 {
		return PrincipalPolicyValidationError{
			field:  "Principal",
			reason: "value length must be at least 1 runes",
		}
	}
	if !_PrincipalPolicy_Principal_Pattern.MatchString(m.GetPrincipal()) {
		return PrincipalPolicyValidationError{
			field:  "Principal",
			reason: "value does not match regex pattern \"^[[:alpha:]][[:word:]\\\\@\\\\.\\\\-]*(\\\\:[[:alpha:]][[:word:]\\\\@\\\\.\\\\-]*)*$\"",
		}
	}
	if !_PrincipalPolicy_Version_Pattern.MatchString(m.GetVersion()) {
		return PrincipalPolicyValidationError{
			field:  "Version",
			reason: "value does not match regex pattern \"^[[:word:]]+$\"",
		}
	}
	if len(m.GetRules()) < 1 {
		return PrincipalPolicyValidationError{
			field:  "Rules",
			reason: "value must contain at least 1 item(s)",
		}
	}
	for idx, item := range m.GetRules() {
		_, _ = idx, item
		if v, ok := interface{}(item).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return PrincipalPolicyValidationError{
					field:  fmt.Sprintf("Rules[%v]", idx),
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}
	if !_PrincipalPolicy_Scope_Pattern.MatchString(m.GetScope()) {
		return PrincipalPolicyValidationError{
			field:  "Scope",
			reason: "value does not match regex pattern \"^([[:alpha:]][[:word:]\\\\-]+(\\\\.[[:alpha:]][[:word:]\\\\-]*)*)*$\"",
		}
	}
	return nil
}
type PrincipalPolicyValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e PrincipalPolicyValidationError) Field() string { return e.field }
func (e PrincipalPolicyValidationError) Reason() string { return e.reason }
func (e PrincipalPolicyValidationError) Cause() error { return e.cause }
func (e PrincipalPolicyValidationError) Key() bool { return e.key }
func (e PrincipalPolicyValidationError) ErrorName() string { return "PrincipalPolicyValidationError" }
func (e PrincipalPolicyValidationError) 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 %sPrincipalPolicy.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
var _ error = PrincipalPolicyValidationError{}
var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = PrincipalPolicyValidationError{}
var _PrincipalPolicy_Principal_Pattern = regexp.MustCompile("^[[:alpha:]][[:word:]\\@\\.\\-]*(\\:[[:alpha:]][[:word:]\\@\\.\\-]*)*$")
var _PrincipalPolicy_Version_Pattern = regexp.MustCompile("^[[:word:]]+$")
var _PrincipalPolicy_Scope_Pattern = regexp.MustCompile("^([[:alpha:]][[:word:]\\-]+(\\.[[:alpha:]][[:word:]\\-]*)*)*$")
func (m *PrincipalRule) Validate() error {
	if m == nil {
		return nil
	}
	if utf8.RuneCountInString(m.GetResource()) < 1 {
		return PrincipalRuleValidationError{
			field:  "Resource",
			reason: "value length must be at least 1 runes",
		}
	}
	if !_PrincipalRule_Resource_Pattern.MatchString(m.GetResource()) {
		return PrincipalRuleValidationError{
			field:  "Resource",
			reason: "value does not match regex pattern \"^[[:alpha:]][[:word:]\\\\@\\\\.\\\\-/]*(\\\\:[[:alpha:]][[:word:]\\\\@\\\\.\\\\-/]*)*$\"",
		}
	}
	if len(m.GetActions()) < 1 {
		return PrincipalRuleValidationError{
			field:  "Actions",
			reason: "value must contain at least 1 item(s)",
		}
	}
	for idx, item := range m.GetActions() {
		_, _ = idx, item
		if v, ok := interface{}(item).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return PrincipalRuleValidationError{
					field:  fmt.Sprintf("Actions[%v]", idx),
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}
	return nil
}
type PrincipalRuleValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e PrincipalRuleValidationError) Field() string { return e.field }
func (e PrincipalRuleValidationError) Reason() string { return e.reason }
func (e PrincipalRuleValidationError) Cause() error { return e.cause }
func (e PrincipalRuleValidationError) Key() bool { return e.key }
func (e PrincipalRuleValidationError) ErrorName() string { return "PrincipalRuleValidationError" }
func (e PrincipalRuleValidationError) 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 %sPrincipalRule.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
var _ error = PrincipalRuleValidationError{}
var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = PrincipalRuleValidationError{}
var _PrincipalRule_Resource_Pattern = regexp.MustCompile("^[[:alpha:]][[:word:]\\@\\.\\-/]*(\\:[[:alpha:]][[:word:]\\@\\.\\-/]*)*$")
func (m *DerivedRoles) Validate() error {
	if m == nil {
		return nil
	}
	if utf8.RuneCountInString(m.GetName()) < 1 {
		return DerivedRolesValidationError{
			field:  "Name",
			reason: "value length must be at least 1 runes",
		}
	}
	if !_DerivedRoles_Name_Pattern.MatchString(m.GetName()) {
		return DerivedRolesValidationError{
			field:  "Name",
			reason: "value does not match regex pattern \"^[[:word:]\\\\-\\\\.]+$\"",
		}
	}
	if len(m.GetDefinitions()) < 1 {
		return DerivedRolesValidationError{
			field:  "Definitions",
			reason: "value must contain at least 1 item(s)",
		}
	}
	for idx, item := range m.GetDefinitions() {
		_, _ = idx, item
		if v, ok := interface{}(item).(interface{ Validate() error }); ok {
			if err := v.Validate(); err != nil {
				return DerivedRolesValidationError{
					field:  fmt.Sprintf("Definitions[%v]", idx),
					reason: "embedded message failed validation",
					cause:  err,
				}
			}
		}
	}
	return nil
}
type DerivedRolesValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e DerivedRolesValidationError) Field() string { return e.field }
func (e DerivedRolesValidationError) Reason() string { return e.reason }
func (e DerivedRolesValidationError) Cause() error { return e.cause }
func (e DerivedRolesValidationError) Key() bool { return e.key }
func (e DerivedRolesValidationError) ErrorName() string { return "DerivedRolesValidationError" }
func (e DerivedRolesValidationError) 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 %sDerivedRoles.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
var _ error = DerivedRolesValidationError{}
var _ interface {
	Field() string
	Reason() string
	Key() bool
	Cause() error
	ErrorName() string
} = DerivedRolesValidationError{}
var _DerivedRoles_Name_Pattern = regexp.MustCompile("^[[:word:]\\-\\.]+$")
func (m *RoleDef) Validate() error {
	if m == nil {
		return nil
	}
	if !_RoleDef_Name_Pattern.MatchString(m.GetName()) {
		return RoleDefValidationError{
			field:  "Name",
			reason: "value does not match regex pattern \"^[[:word:]\\\\-\\\\.]+$\"",
		}
	}
	if len(m.GetParentRoles()) < 1 {
		return RoleDefValidationError{
			field:  "ParentRoles",
			reason: "value must contain at least 1 item(s)",
		}
	}
	_RoleDef_ParentRoles_Unique := make(map[string]struct{}, len(m.GetParentRoles()))
	for idx, item := range m.GetParentRoles() {
		_, _ = idx, item
		if _, exists := _RoleDef_ParentRoles_Unique[item]; exists {
			return RoleDefValidationError{
				field:  fmt.Sprintf("ParentRoles[%v]", idx),
				reason: "repeated value must contain unique items",
			}
		} else {
			_RoleDef_ParentRoles_Unique[item] = struct{}{}
		}
		if !_RoleDef_ParentRoles_Pattern.MatchString(item) {
			return RoleDefValidationError{
				field:  fmt.Sprintf("ParentRoles[%v]", idx),
				reason: "value does not match regex pattern \"^[[:word:]\\\\-\\\\.]+$\"",
			}
		}
	}
	if v, ok := interface{}(m.GetCondition()).(interface{ Validate() error }); ok {
		if err := v.Validate(); err != nil {
			return RoleDefValidationError{
				field:  "Condition",
				reason: "embedded message failed validation",
				cause:  err,
			}
		}
	}
	return nil
}
type RoleDefValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e RoleDefValidationError) Field() string { return e.field }
func (e RoleDefValidationError) Reason() string { return e.reason }
func (e RoleDefValidationError) Cause() error { return e.cause }
func (e RoleDefValidationError) Key() bool { return e.key }
func (e RoleDefValidationError) ErrorName() string { return "RoleDefValidationError" }