package jsonschema

// CompilerContext provides helpers for
// compiling a [Vocabulary].
type CompilerContext struct {
	c *objCompiler
}

func ( *CompilerContext) ( []string) *Schema {
	 := .c.up.ptr
	for ,  := range  {
		 = .append()
	}
	return .c.enqueuePtr()
}

func ( *CompilerContext) ( string) (*Schema, error) {
	return .c.enqueueRefVal()
}

// Vocabulary defines a set of keywords, their syntax and
// their semantics.
type Vocabulary struct {
	// URL identifier for this Vocabulary.
	URL string

	// Schema that is used to validate the keywords that is introduced by this
	// vocabulary.
	Schema *Schema

	// Subschemas lists the possible locations of subschemas introduced by
	// this vocabulary.
	Subschemas []SchemaPath

	// Compile compiles the keywords(introduced by this vocabulary) in obj into [SchemaExt].
	// If obj does not contain any keywords introduced by this vocabulary, nil SchemaExt must
	// be returned.
	Compile func(ctx *CompilerContext, obj map[string]any) (SchemaExt, error)
}

// --

// SchemaExt is compled form of vocabulary.
type SchemaExt interface {
	// Validate validates v against and errors if any are reported
	// to ctx.
	Validate(ctx *ValidatorContext, v any)
}

// ValidatorContext provides helpers for
// validating with [SchemaExt].
type ValidatorContext struct {
	vd *validator
}

// ValueLocation returns location of value as jsonpath token array.
func ( *ValidatorContext) () []string {
	return .vd.vloc
}

// Validate validates v with sch. vpath gives path of v from current context value.
func ( *ValidatorContext) ( *Schema,  any,  []string) error {
	switch len() {
	case 0:
		return .vd.validateSelf(, "", false)
	case 1:
		return .vd.validateVal(, , [0])
	default:
		return .vd.validateValue(, , )
	}
}

// EvaluatedProp marks given property of current object as evaluated.
func ( *ValidatorContext) ( string) {
	delete(.vd.uneval.props, )
}

// EvaluatedItem marks items at given index of current array as evaluated.
func ( *ValidatorContext) ( int) {
	delete(.vd.uneval.items, )
}

// AddError reports validation-error of given kind.
func ( *ValidatorContext) ( ErrorKind) {
	.vd.addError()
}

// AddErrors reports validation-errors of given kind.
func ( *ValidatorContext) ( []*ValidationError,  ErrorKind) {
	.vd.addErrors(, )
}

// AddErr reports the given err. This is typically used to report
// the error created by subschema validation.
//
// NOTE that err must be of type *ValidationError.
func ( *ValidatorContext) ( error) {
	.vd.addErr()
}

func ( *ValidatorContext) (,  any) (bool, error) {
	,  := equals(, )
	if  != nil {
		return false, .vd.error()
	}
	return , nil
}

func ( *ValidatorContext) ( []any) (int, int, error) {
	, ,  := duplicates()
	if  != nil {
		return -1, -1, .vd.error()
	}
	return , , nil
}