func (obj *Object) MustGetString(attr string) string {
	result, err := obj.GetString(attr)
	if err != nil {
		panic(err)
	}
	return result
}
MustGetString is like GetString, but it panic in case of error.
package vt
import (
	"bytes"
	"encoding/json"
	"fmt"
	"time"
	gojsonq "github.com/thedevsaddam/gojsonq/v2"
)
type objectData struct {
	ID                string                       `json:"id,omitempty"`
	Type              string                       `json:"type,omitempty"`
	Attributes        map[string]interface{}       `json:"attributes,omitempty"`
	ContextAttributes map[string]interface{}       `json:"context_attributes,omitempty"`
	Relationships     map[string]*relationshipData `json:"relationships,omitempty"`
	Links             *Links                       `json:"links,omitempty"`
}
type Object struct {
	data objectData
	jsonq *gojsonq.JSONQ
	modifiedAttributes []string
}
type Links struct {
	Self string `json:"self,omitempty"`
	Next string `json:"next,omitempty"`
}
func NewObject(objType string) *Object {
	return &Object{data: objectData{
		Type:       objType,
		Attributes: make(map[string]interface{})}}
}
func NewObjectWithID(objType, id string) *Object {
	return &Object{data: objectData{
		Type:       objType,
		ID:         id,
		Attributes: make(map[string]interface{})}}
}
func (obj *Object) ID() string {
	return obj.data.ID
}
func (obj *Object) Type() string {
	return obj.data.Type
}
func (obj *Object) Attributes() []string {
	result := make([]string, len(obj.data.Attributes))
	i := 0
	for attr := range obj.data.Attributes {
		result[i] = attr
		i++
	}
	return result
}
func (obj *Object) ContextAttributes() []string {
	result := make([]string, len(obj.data.ContextAttributes))
	i := 0
	for attr := range obj.data.ContextAttributes {
		result[i] = attr
		i++
	}
	return result
}
func (obj *Object) Relationships() []string {
	result := make([]string, len(obj.data.Relationships))
	i := 0
	for rel := range obj.data.Relationships {
		result[i] = rel
		i++
	}
	return result
}
func (obj *Object) MarshalJSON() ([]byte, error) {
	return json.Marshal(obj.data)
}
func (obj *Object) UnmarshalJSON(data []byte) error {
	decoder := json.NewDecoder(bytes.NewReader(data))
	decoder.UseNumber()
	od := objectData{}
	if err := decoder.Decode(&od); err != nil {
		return err
	}
	obj.data = od
	for _, v := range obj.data.Relationships {
		var o Object
		if err := json.Unmarshal(v.Data, &o); err == nil {
			v.IsOneToOne = true
			if o.data.ID == "" && o.data.Type == "" {
				v.Objects = nil
			} else {
				v.Objects = append(v.Objects, &o)
			}
		} else {
			if err := json.Unmarshal(v.Data, &v.Objects); err != nil {
				return err
			}
		}
	}
	return nil
}
func (obj *Object) getContextAttributeNumber(name string) (n json.Number, err error) {
	if attrValue, attrExists := obj.data.ContextAttributes[name]; attrExists {
		n, isNumber := attrValue.(json.Number)
		if !isNumber {
			err = fmt.Errorf("context attribute \"%s\" is not a number", name)
		}
		return n, err
	}
	return n, fmt.Errorf("context attribute \"%s\" does not exists", name)
}
type decoder struct{}
func (d *decoder) Decode(data []byte, v interface{}) error {
	dec := json.NewDecoder(bytes.NewReader(data))
	dec.UseNumber()
	return dec.Decode(v)
}
func (obj *Object) getJsonQ() (*gojsonq.JSONQ, error) {
	if obj.jsonq == nil || len(obj.modifiedAttributes) > 0 {
		if j, err := json.Marshal(obj.data.Attributes); err == nil {
			obj.jsonq = gojsonq.New(gojsonq.WithDecoder(&decoder{})).FromString(string(j))
		} else {
			return nil, err
		}
	} else {
		obj.jsonq.Reset()
	}
	return obj.jsonq, nil
}
func (obj *Object) Get(attr string) (interface{}, error) {
	v, err := obj.getJsonQ()
	if err != nil {
		return nil, err
	}
	results := v.Find(attr)
	if err := v.Error(); err != nil {
		return nil, err
	}
	return results, nil
}
func (obj *Object) GetInt64(attr string) (int64, error) {
	n, err := obj.Get(attr)
	if err != nil {
		return 0, err
	}
	value, ok := n.(json.Number)
	if !ok {
		return 0, fmt.Errorf("attr %v is not a number", attr)
	}
	return value.Int64()
}
func (obj *Object) MustGetInt64(attr string) int64 {
	result, err := obj.GetInt64(attr)
	if err != nil {
		panic(err)
	}
	return result
}
func (obj *Object) GetFloat64(attr string) (float64, error) {
	n, err := obj.Get(attr)
	if err != nil {
		return 0, err
	}
	value, ok := n.(json.Number)
	if !ok {
		return 0, fmt.Errorf("attr %v is not a number", attr)
	}
	return value.Float64()
}
func (obj *Object) MustGetFloat64(attr string) float64 {
	result, err := obj.GetFloat64(attr)
	if err != nil {
		panic(err)
	}
	return result
}
func (obj *Object) GetString(attr string) (s string, err error) {
	value, err := obj.Get(attr)
	if err != nil {
		return s, err
	}
	s, isString := value.(string)
	if !isString {
		err = fmt.Errorf("attribute \"%s\" is not a string", attr)
	}
	return s, err
}