package jsonschema

import (
	
	
	

	
	
	
)

var defaultPrinter = message.NewPrinter(language.English)

// format ---

func ( *ValidationError) () string {
	if ,  := .ErrorKind.(*kind.Reference);  {
		return .URL
	} else {
		return .SchemaURL
	}
}

func ( *ValidationError) () string {
	var  string
	var  []string
	if ,  := .ErrorKind.(*kind.Reference);  {
		 = .URL
		 = nil
	} else {
		 = .SchemaURL
		 = .ErrorKind.KeywordPath()
	}
	return fmt.Sprintf("%s%s", , encode(jsonPtr()))
}

func ( *ValidationError) () bool {
	if len(.Causes) == 1 {
		,  := .ErrorKind.(*kind.Reference)
		return 
	}
	return false
}

func ( *ValidationError) ( *strings.Builder,  bool,  int,  string,  *message.Printer) {
	if !.skip() {
		if  > 0 {
			.WriteByte('\n')
			for  := 0;  < -1; ++ {
				.WriteString("  ")
			}
			.WriteString("- ")
		}
		 =  + 1

		 := 
		 = .absoluteKeywordLocation()

		if ,  := .ErrorKind.(*kind.Schema);  {
			.WriteString(.ErrorKind.LocalizedString())
		} else {
			.WriteString(.Sprintf("at %s", quote(jsonPtr(.InstanceLocation))))
			if  {
				 := 
				if  != "" {
					,  := split()
					,  := split()
					if  ==  {
						 = fmt.Sprintf("S#%s", )
					}
				}
				fmt.Fprintf(, " [%s]", )
			}
			fmt.Fprintf(, ": %s", .ErrorKind.LocalizedString())
		}
	}
	for ,  := range .Causes {
		.(, , , , )
	}
}

func ( *ValidationError) () string {
	return .LocalizedError(defaultPrinter)
}

func ( *ValidationError) ( *message.Printer) string {
	var  strings.Builder
	.display(&, false, 0, "", )
	return .String()
}

func ( *ValidationError) () string {
	return .LocalizedGoString(defaultPrinter)
}

func ( *ValidationError) ( *message.Printer) string {
	var  strings.Builder
	.display(&, true, 0, "", )
	return .String()
}

func jsonPtr( []string) string {
	var  strings.Builder
	for ,  := range  {
		.WriteByte('/')
		.WriteString(escape())
	}
	return .String()
}

// --

// Flag is output format with simple boolean property valid.
type FlagOutput struct {
	Valid bool `json:"valid"`
}

// The `Flag` output format, merely the boolean result.
func ( *ValidationError) () *FlagOutput {
	return &FlagOutput{Valid: false}
}

// --

type OutputUnit struct {
	Valid                   bool         `json:"valid"`
	KeywordLocation         string       `json:"keywordLocation"`
	AbsoluteKeywordLocation string       `json:"AbsoluteKeywordLocation,omitempty"`
	InstanceLocation        string       `json:"instanceLocation"`
	Error                   *OutputError `json:"error,omitempty"`
	Errors                  []OutputUnit `json:"errors,omitempty"`
}

type OutputError struct {
	Kind ErrorKind
	p    *message.Printer
}

func ( OutputError) () string {
	return .Kind.LocalizedString(.p)
}

func ( OutputError) () ([]byte, error) {
	return json.Marshal(.Kind.LocalizedString(.p))
}

// The `Basic` structure, a flat list of output units.
func ( *ValidationError) () *OutputUnit {
	return .LocalizedBasicOutput(defaultPrinter)
}

func ( *ValidationError) ( *message.Printer) *OutputUnit {
	 := .output(true, false, "", "", )
	return &
}

// The `Detailed` structure, based on the schema.
func ( *ValidationError) () *OutputUnit {
	return .LocalizedDetailedOutput(defaultPrinter)
}

func ( *ValidationError) ( *message.Printer) *OutputUnit {
	 := .output(false, false, "", "", )
	return &
}

func ( *ValidationError) (,  bool, ,  string,  *message.Printer) OutputUnit {
	if ! {
		if ,  := .ErrorKind.(*kind.Reference);  {
			 = true
		}
	}
	if  != "" {
		 += .SchemaURL[len():]
		if ,  := .ErrorKind.(*kind.Reference);  {
			 += jsonPtr(.KeywordPath())
		}
	}
	 = .schemaURL()

	 := 
	if ,  := .ErrorKind.(*kind.Reference); ! {
		 += jsonPtr(.ErrorKind.KeywordPath())
	}

	 := OutputUnit{
		Valid:            false,
		InstanceLocation: jsonPtr(.InstanceLocation),
		KeywordLocation:  ,
	}
	if  {
		.AbsoluteKeywordLocation = .absoluteKeywordLocation()
	}
	for ,  := range .Causes {
		 := .(, , , , )
		if .skip() {
			 = .Errors[0]
		}
		if  {
			 := .Errors
			.Errors = nil
			.Error = &OutputError{.ErrorKind, }
			.Errors = append(.Errors, )
			if len() > 0 {
				.Errors = append(.Errors, ...)
			}
		} else {
			.Errors = append(.Errors, )
		}
	}
	if len(.Errors) == 0 {
		.Error = &OutputError{.ErrorKind, }
	}
	return 
}