package kind

import (
	
	
	

	
)

// --

type InvalidJsonValue struct {
	Value any
}

func (*InvalidJsonValue) () []string {
	return nil
}

func ( *InvalidJsonValue) ( *message.Printer) string {
	return .Sprintf("invalid jsonType %T", .Value)
}

// --

type Schema struct {
	Location string
}

func (*Schema) () []string {
	return nil
}

func ( *Schema) ( *message.Printer) string {
	return .Sprintf("jsonschema validation failed with %s", quote(.Location))
}

// --

type Group struct{}

func (*Group) () []string {
	return nil
}

func (*Group) ( *message.Printer) string {
	return .Sprintf("validation failed")
}

// --

type Not struct{}

func (*Not) () []string {
	return nil
}

func (*Not) ( *message.Printer) string {
	return .Sprintf("'not' failed")
}

// --

type AllOf struct{}

func (*AllOf) () []string {
	return []string{"allOf"}
}

func (*AllOf) ( *message.Printer) string {
	return .Sprintf("'allOf' failed")
}

// --

type AnyOf struct{}

func (*AnyOf) () []string {
	return []string{"anyOf"}
}

func (*AnyOf) ( *message.Printer) string {
	return .Sprintf("'anyOf' failed")
}

// --

type OneOf struct {
	// Subschemas gives indexes of Subschemas that have matched.
	// Value nil, means none of the subschemas matched.
	Subschemas []int
}

func (*OneOf) () []string {
	return []string{"oneOf"}
}

func ( *OneOf) ( *message.Printer) string {
	if len(.Subschemas) == 0 {
		return .Sprintf("'oneOf' failed, none matched")
	}
	return .Sprintf("'oneOf' failed, subschemas %d, %d matched", .Subschemas[0], .Subschemas[1])
}

//--

type FalseSchema struct{}

func (*FalseSchema) () []string {
	return nil
}

func (*FalseSchema) ( *message.Printer) string {
	return .Sprintf("false schema")
}

// --

type RefCycle struct {
	URL              string
	KeywordLocation1 string
	KeywordLocation2 string
}

func (*RefCycle) () []string {
	return nil
}

func ( *RefCycle) ( *message.Printer) string {
	return .Sprintf("both %s and %s resolve to %q causing reference cycle", .KeywordLocation1, .KeywordLocation2, .URL)
}

// --

type Type struct {
	Got  string
	Want []string
}

func (*Type) () []string {
	return []string{"type"}
}

func ( *Type) ( *message.Printer) string {
	 := strings.Join(.Want, " or ")
	return .Sprintf("got %s, want %s", .Got, )
}

// --

type Enum struct {
	Got  any
	Want []any
}

// KeywordPath implements jsonschema.ErrorKind.
func (*Enum) () []string {
	return []string{"enum"}
}

func ( *Enum) ( *message.Printer) string {
	 := true
:
	for ,  := range .Want {
		switch .(type) {
		case []any, map[string]any:
			 = false
			break 
		}
	}
	if  {
		if len(.Want) == 1 {
			return .Sprintf("value must be %s", display(.Want[0]))
		}
		var  []string
		for ,  := range .Want {
			 = append(, display())
		}
		return .Sprintf("value must be one of %s", strings.Join(, ", "))
	}
	return .Sprintf("'enum' failed")
}

// --

type Const struct {
	Got  any
	Want any
}

func (*Const) () []string {
	return []string{"const"}
}

func ( *Const) ( *message.Printer) string {
	switch want := .Want.(type) {
	case []any, map[string]any:
		return .Sprintf("'const' failed")
	default:
		return .Sprintf("value must be %s", display())
	}
}

// --

type Format struct {
	Got  any
	Want string
	Err  error
}

func (*Format) () []string {
	return []string{"format"}
}

func ( *Format) ( *message.Printer) string {
	return .Sprintf("%s is not valid %s: %v", display(.Got), .Want, localizedError(.Err, ))
}

// --

type Reference struct {
	Keyword string
	URL     string
}

func ( *Reference) () []string {
	return []string{.Keyword}
}

func (*Reference) ( *message.Printer) string {
	return .Sprintf("validation failed")
}

// --

type MinProperties struct {
	Got, Want int
}

func (*MinProperties) () []string {
	return []string{"minProperties"}
}

func ( *MinProperties) ( *message.Printer) string {
	return .Sprintf("minProperties: got %d, want %d", .Got, .Want)
}

// --

type MaxProperties struct {
	Got, Want int
}

func (*MaxProperties) () []string {
	return []string{"maxProperties"}
}

func ( *MaxProperties) ( *message.Printer) string {
	return .Sprintf("maxProperties: got %d, want %d", .Got, .Want)
}

// --

type MinItems struct {
	Got, Want int
}

func (*MinItems) () []string {
	return []string{"minItems"}
}

func ( *MinItems) ( *message.Printer) string {
	return .Sprintf("minItems: got %d, want %d", .Got, .Want)
}

// --

type MaxItems struct {
	Got, Want int
}

func (*MaxItems) () []string {
	return []string{"maxItems"}
}

func ( *MaxItems) ( *message.Printer) string {
	return .Sprintf("maxItems: got %d, want %d", .Got, .Want)
}

// --

type AdditionalItems struct {
	Count int
}

func (*AdditionalItems) () []string {
	return []string{"additionalItems"}
}

func ( *AdditionalItems) ( *message.Printer) string {
	return .Sprintf("last %d additionalItem(s) not allowed", .Count)
}

// --

type Required struct {
	Missing []string
}

func (*Required) () []string {
	return []string{"required"}
}

func ( *Required) ( *message.Printer) string {
	if len(.Missing) == 1 {
		return .Sprintf("missing property %s", quote(.Missing[0]))
	}
	return .Sprintf("missing properties %s", joinQuoted(.Missing, ", "))
}

// --

type Dependency struct {
	Prop    string   // dependency of prop that failed
	Missing []string // missing props
}

func ( *Dependency) () []string {
	return []string{"dependency", .Prop}
}

func ( *Dependency) ( *message.Printer) string {
	return .Sprintf("properties %s required, if %s exists", joinQuoted(.Missing, ", "), quote(.Prop))
}

// --

type DependentRequired struct {
	Prop    string   // dependency of prop that failed
	Missing []string // missing props
}

func ( *DependentRequired) () []string {
	return []string{"dependentRequired", .Prop}
}

func ( *DependentRequired) ( *message.Printer) string {
	return .Sprintf("properties %s required, if %s exists", joinQuoted(.Missing, ", "), quote(.Prop))
}

// --

type AdditionalProperties struct {
	Properties []string
}

func (*AdditionalProperties) () []string {
	return []string{"additionalProperties"}
}

func ( *AdditionalProperties) ( *message.Printer) string {
	return .Sprintf("additional properties %s not allowed", joinQuoted(.Properties, ", "))
}

// --

type PropertyNames struct {
	Property string
}

func (*PropertyNames) () []string {
	return []string{"propertyNames"}
}

func ( *PropertyNames) ( *message.Printer) string {
	return .Sprintf("invalid propertyName %s", quote(.Property))
}

// --

type UniqueItems struct {
	Duplicates [2]int
}

func (*UniqueItems) () []string {
	return []string{"uniqueItems"}
}

func ( *UniqueItems) ( *message.Printer) string {
	return .Sprintf("items at %d and %d are equal", .Duplicates[0], .Duplicates[1])
}

// --

type Contains struct{}

func (*Contains) () []string {
	return []string{"contains"}
}

func (*Contains) ( *message.Printer) string {
	return .Sprintf("no items match contains schema")
}

// --

type MinContains struct {
	Got  []int
	Want int
}

func (*MinContains) () []string {
	return []string{"minContains"}
}

func ( *MinContains) ( *message.Printer) string {
	if len(.Got) == 0 {
		return .Sprintf("min %d items required to match contains schema, but none matched", .Want)
	} else {
		 := fmt.Sprintf("%v", .Got)
		return .Sprintf("min %d items required to match contains schema, but matched %d items at %v", .Want, len(.Got), [1:len()-1])
	}
}

// --

type MaxContains struct {
	Got  []int
	Want int
}

func (*MaxContains) () []string {
	return []string{"maxContains"}
}

func ( *MaxContains) ( *message.Printer) string {
	 := fmt.Sprintf("%v", .Got)
	return .Sprintf("max %d items required to match contains schema, but matched %d items at %v", .Want, len(.Got), [1:len()-1])
}

// --

type MinLength struct {
	Got, Want int
}

func (*MinLength) () []string {
	return []string{"minLength"}
}

func ( *MinLength) ( *message.Printer) string {
	return .Sprintf("minLength: got %d, want %d", .Got, .Want)
}

// --

type MaxLength struct {
	Got, Want int
}

func (*MaxLength) () []string {
	return []string{"maxLength"}
}

func ( *MaxLength) ( *message.Printer) string {
	return .Sprintf("maxLength: got %d, want %d", .Got, .Want)
}

// --

type Pattern struct {
	Got  string
	Want string
}

func (*Pattern) () []string {
	return []string{"pattern"}
}

func ( *Pattern) ( *message.Printer) string {
	return .Sprintf("%s does not match pattern %s", quote(.Got), quote(.Want))
}

// --

type ContentEncoding struct {
	Want string
	Err  error
}

func (*ContentEncoding) () []string {
	return []string{"contentEncoding"}
}

func ( *ContentEncoding) ( *message.Printer) string {
	return .Sprintf("value is not %s encoded: %v", quote(.Want), localizedError(.Err, ))
}

// --

type ContentMediaType struct {
	Got  []byte
	Want string
	Err  error
}

func (*ContentMediaType) () []string {
	return []string{"contentMediaType"}
}

func ( *ContentMediaType) ( *message.Printer) string {
	return .Sprintf("value is not of mediatype %s: %v", quote(.Want), .Err)
}

// --

type ContentSchema struct{}

func (*ContentSchema) () []string {
	return []string{"contentSchema"}
}

func (*ContentSchema) ( *message.Printer) string {
	return .Sprintf("'contentSchema' failed")
}

// --

type Minimum struct {
	Got  *big.Rat
	Want *big.Rat
}

func (*Minimum) () []string {
	return []string{"minimum"}
}

func ( *Minimum) ( *message.Printer) string {
	,  := .Got.Float64()
	,  := .Want.Float64()
	return .Sprintf("minimum: got %v, want %v", , )
}

// --

type Maximum struct {
	Got  *big.Rat
	Want *big.Rat
}

func (*Maximum) () []string {
	return []string{"maximum"}
}

func ( *Maximum) ( *message.Printer) string {
	,  := .Got.Float64()
	,  := .Want.Float64()
	return .Sprintf("maximum: got %v, want %v", , )
}

// --

type ExclusiveMinimum struct {
	Got  *big.Rat
	Want *big.Rat
}

func (*ExclusiveMinimum) () []string {
	return []string{"exclusiveMinimum"}
}

func ( *ExclusiveMinimum) ( *message.Printer) string {
	,  := .Got.Float64()
	,  := .Want.Float64()
	return .Sprintf("exclusiveMinimum: got %v, want %v", , )
}

// --

type ExclusiveMaximum struct {
	Got  *big.Rat
	Want *big.Rat
}

func (*ExclusiveMaximum) () []string {
	return []string{"exclusiveMaximum"}
}

func ( *ExclusiveMaximum) ( *message.Printer) string {
	,  := .Got.Float64()
	,  := .Want.Float64()
	return .Sprintf("exclusiveMaximum: got %v, want %v", , )
}

// --

type MultipleOf struct {
	Got  *big.Rat
	Want *big.Rat
}

func (*MultipleOf) () []string {
	return []string{"multipleOf"}
}

func ( *MultipleOf) ( *message.Printer) string {
	,  := .Got.Float64()
	,  := .Want.Float64()
	return .Sprintf("multipleOf: got %v, want %v", , )
}

// --

func quote( string) string {
	 = fmt.Sprintf("%q", )
	 = strings.ReplaceAll(, `\"`, `"`)
	 = strings.ReplaceAll(, `'`, `\'`)
	return "'" + [1:len()-1] + "'"
}

func joinQuoted( []string,  string) string {
	var  strings.Builder
	for ,  := range  {
		if .Len() > 0 {
			.WriteString()
		}
		.WriteString(quote())
	}
	return .String()
}

// to be used only for primitive.
func display( any) string {
	switch v := .(type) {
	case string:
		return quote()
	case []any, map[string]any:
		return "value"
	default:
		return fmt.Sprintf("%v", )
	}
}

func localizedError( error,  *message.Printer) string {
	if ,  := .(interface{ (*message.Printer) string });  {
		return .()
	}
	return .Error()
}