package json

import (
	

	
)

// CreatePath creates JSON Path.
//
// JSON Path rule
// $   : root object or element. The JSON Path format must start with this operator, which refers to the outermost level of the JSON-formatted string.
// .   : child operator. You can identify child values using dot-notation.
// ..  : recursive descent.
// []  : subscript operator. If the JSON object is an array, you can use brackets to specify the array index.
// [*] : all objects/elements for array.
//
// Reserved words must be properly escaped when included in Path.
//
// Escape Rule
// single quote style escape: e.g.) `$['a.b'].c`
// double quote style escape: e.g.) `$."a.b".c`
func ( string) (*Path, error) {
	,  := decoder.PathString().Build()
	if  != nil {
		return nil, 
	}
	return &Path{path: }, nil
}

// Path represents JSON Path.
type Path struct {
	path *decoder.Path
}

// RootSelectorOnly whether only the root selector ($) is used.
func ( *Path) () bool {
	return .path.RootSelectorOnly
}

// UsedSingleQuotePathSelector whether single quote-based escaping was done when building the JSON Path.
func ( *Path) () bool {
	return .path.SingleQuotePathSelector
}

// UsedSingleQuotePathSelector whether double quote-based escaping was done when building the JSON Path.
func ( *Path) () bool {
	return .path.DoubleQuotePathSelector
}

// Extract extracts a specific JSON string.
func ( *Path) ( []byte,  ...DecodeOptionFunc) ([][]byte, error) {
	return extractFromPath(, , ...)
}

// PathString returns original JSON Path string.
func ( *Path) () string {
	return .path.String()
}

// Unmarshal extract and decode the value of the part corresponding to JSON Path from the input data.
func ( *Path) ( []byte,  interface{},  ...DecodeOptionFunc) error {
	,  := extractFromPath(, , ...)
	if  != nil {
		return 
	}
	 := make([]interface{}, 0, len())
	for ,  := range  {
		var  interface{}
		if  := Unmarshal(, &);  != nil {
			return 
		}
		 = append(, )
	}
	if  := decoder.AssignValue(reflect.ValueOf(), reflect.ValueOf());  != nil {
		return 
	}
	return nil
}

// Get extract and substitute the value of the part corresponding to JSON Path from the input value.
func ( *Path) (,  interface{}) error {
	return .path.Get(reflect.ValueOf(), reflect.ValueOf())
}