// Code generated by ObjectBox; DO NOT EDIT.
// Learn more about defining entities and generating this file - visit https://golang.objectbox.io/entity-annotations

package object

import (
	"errors"
	"github.com/google/flatbuffers/go"
	"github.com/objectbox/objectbox-go/objectbox"
	"github.com/objectbox/objectbox-go/objectbox/fbutils"
)

type taskIndexed_EntityInfo struct {
	objectbox.Entity
	Uid uint64
}

var TaskIndexedBinding = taskIndexed_EntityInfo{
	Entity: objectbox.Entity{
		Id: 5,
	},
	Uid: 7144924247938981575,
}

// TaskIndexed_ contains type-based Property helpers to facilitate some common operations such as Queries.
var TaskIndexed_ = struct {
	Id        *objectbox.PropertyUint64
	Uid       *objectbox.PropertyString
	UidValue  *objectbox.PropertyString
	UidHash   *objectbox.PropertyString
	UidHash64 *objectbox.PropertyString
	UidInt    *objectbox.PropertyUint64
	Name      *objectbox.PropertyString
	Priority  *objectbox.PropertyInt
	Group     *objectbox.PropertyString
	Place     *objectbox.PropertyString
	Source    *objectbox.PropertyString
}{
	Id: &objectbox.PropertyUint64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     1,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	Uid: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     2,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	UidValue: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     3,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	UidHash: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     4,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	UidHash64: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     5,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	UidInt: &objectbox.PropertyUint64{
		BaseProperty: &objectbox.BaseProperty{
			Id:     6,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	Name: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     7,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	Priority: &objectbox.PropertyInt{
		BaseProperty: &objectbox.BaseProperty{
			Id:     8,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	Group: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     9,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	Place: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     10,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
	Source: &objectbox.PropertyString{
		BaseProperty: &objectbox.BaseProperty{
			Id:     11,
			Entity: &TaskIndexedBinding.Entity,
		},
	},
}

// GeneratorVersion is called by ObjectBox to verify the compatibility of the generator used to generate this code
func (taskIndexed_EntityInfo) GeneratorVersion() int {
	return 6
}

// AddToModel is called by ObjectBox during model build
func (taskIndexed_EntityInfo) AddToModel(model *objectbox.Model) {
	model.Entity("TaskIndexed", 5, 7144924247938981575)
	model.Property("Id", 6, 1, 161231572858529631)
	model.PropertyFlags(1)
	model.Property("Uid", 9, 2, 7259475919510918339)
	model.PropertyFlags(2080)
	model.PropertyIndex(3, 7373105480197164748)
	model.Property("UidValue", 9, 3, 3287288577352441706)
	model.PropertyFlags(40)
	model.PropertyIndex(4, 3930927879439176946)
	model.Property("UidHash", 9, 4, 4706154865122290029)
	model.PropertyFlags(2080)
	model.PropertyIndex(5, 2217592893536642650)
	model.Property("UidHash64", 9, 5, 1929546706668609706)
	model.PropertyFlags(4128)
	model.PropertyIndex(6, 6392442863481646880)
	model.Property("UidInt", 6, 6, 3706853784096366226)
	model.PropertyFlags(8232)
	model.PropertyIndex(7, 2627038740284806767)
	model.Property("Name", 9, 7, 6303220950515014660)
	model.PropertyFlags(2048)
	model.PropertyIndex(8, 4035568504096476779)
	model.Property("Priority", 6, 8, 959367522974354090)
	model.PropertyFlags(8)
	model.PropertyIndex(9, 2914295034816259174)
	model.Property("Group", 9, 9, 1395437218309923052)
	model.PropertyFlags(8)
	model.PropertyIndex(10, 6745438398739480977)
	model.Property("Place", 9, 10, 2897681629866238117)
	model.PropertyFlags(2048)
	model.PropertyIndex(11, 3398579248012586914)
	model.Property("Source", 9, 11, 5974317550424871033)
	model.PropertyFlags(4096)
	model.PropertyIndex(12, 3317123977833389635)
	model.EntityLastPropertyId(11, 5974317550424871033)
}

// GetId is called by ObjectBox during Put operations to check for existing ID on an object
func (taskIndexed_EntityInfo) GetId(object interface{}) (uint64, error) {
	return object.(*TaskIndexed).Id, nil
}

// SetId is called by ObjectBox during Put to update an ID on an object that has just been inserted
func (taskIndexed_EntityInfo) SetId(object interface{}, id uint64) error {
	object.(*TaskIndexed).Id = id
	return nil
}

// PutRelated is called by ObjectBox to put related entities before the object itself is flattened and put
func (taskIndexed_EntityInfo) PutRelated(ob *objectbox.ObjectBox, object interface{}, id uint64) error {
	return nil
}

// Flatten is called by ObjectBox to transform an object to a FlatBuffer
func (taskIndexed_EntityInfo) Flatten(object interface{}, fbb *flatbuffers.Builder, id uint64) error {
	obj := object.(*TaskIndexed)
	var offsetUid = fbutils.CreateStringOffset(fbb, obj.Uid)
	var offsetUidValue = fbutils.CreateStringOffset(fbb, obj.UidValue)
	var offsetUidHash = fbutils.CreateStringOffset(fbb, obj.UidHash)
	var offsetUidHash64 = fbutils.CreateStringOffset(fbb, obj.UidHash64)
	var offsetName = fbutils.CreateStringOffset(fbb, obj.Name)
	var offsetGroup = fbutils.CreateStringOffset(fbb, obj.Group)
	var offsetPlace = fbutils.CreateStringOffset(fbb, obj.Place)
	var offsetSource = fbutils.CreateStringOffset(fbb, obj.Source)

	// build the FlatBuffers object
	fbb.StartObject(11)
	fbutils.SetUint64Slot(fbb, 0, id)
	fbutils.SetUOffsetTSlot(fbb, 1, offsetUid)
	fbutils.SetUOffsetTSlot(fbb, 2, offsetUidValue)
	fbutils.SetUOffsetTSlot(fbb, 3, offsetUidHash)
	fbutils.SetUOffsetTSlot(fbb, 4, offsetUidHash64)
	fbutils.SetUint64Slot(fbb, 5, obj.UidInt)
	fbutils.SetUOffsetTSlot(fbb, 6, offsetName)
	fbutils.SetInt64Slot(fbb, 7, int64(obj.Priority))
	fbutils.SetUOffsetTSlot(fbb, 8, offsetGroup)
	fbutils.SetUOffsetTSlot(fbb, 9, offsetPlace)
	fbutils.SetUOffsetTSlot(fbb, 10, offsetSource)
	return nil
}

// Load is called by ObjectBox to load an object from a FlatBuffer
func (taskIndexed_EntityInfo) Load(ob *objectbox.ObjectBox, bytes []byte) (interface{}, error) {
	if len(bytes) == 0 { // sanity check, should "never" happen
		return nil, errors.New("can't deserialize an object of type 'TaskIndexed' - no data received")
	}

	var table = &flatbuffers.Table{
		Bytes: bytes,
		Pos:   flatbuffers.GetUOffsetT(bytes),
	}

	var propId = table.GetUint64Slot(4, 0)

	return &TaskIndexed{
		Id:        propId,
		Uid:       fbutils.GetStringSlot(table, 6),
		UidValue:  fbutils.GetStringSlot(table, 8),
		UidHash:   fbutils.GetStringSlot(table, 10),
		UidHash64: fbutils.GetStringSlot(table, 12),
		UidInt:    fbutils.GetUint64Slot(table, 14),
		Name:      fbutils.GetStringSlot(table, 16),
		Priority:  fbutils.GetIntSlot(table, 18),
		Group:     fbutils.GetStringSlot(table, 20),
		Place:     fbutils.GetStringSlot(table, 22),
		Source:    fbutils.GetStringSlot(table, 24),
	}, nil
}

// MakeSlice is called by ObjectBox to construct a new slice to hold the read objects
func (taskIndexed_EntityInfo) MakeSlice(capacity int) interface{} {
	return make([]*TaskIndexed, 0, capacity)
}

// AppendToSlice is called by ObjectBox to fill the slice of the read objects
func (taskIndexed_EntityInfo) AppendToSlice(slice interface{}, object interface{}) interface{} {
	if object == nil {
		return append(slice.([]*TaskIndexed), nil)
	}
	return append(slice.([]*TaskIndexed), object.(*TaskIndexed))
}

// Box provides CRUD access to TaskIndexed objects
type TaskIndexedBox struct {
	*objectbox.Box
}

// BoxForTaskIndexed opens a box of TaskIndexed objects
func BoxForTaskIndexed(ob *objectbox.ObjectBox) *TaskIndexedBox {
	return &TaskIndexedBox{
		Box: ob.InternalBox(5),
	}
}

// Put synchronously inserts/updates a single object.
// In case the Id is not specified, it would be assigned automatically (auto-increment).
// When inserting, the TaskIndexed.Id property on the passed object will be assigned the new ID as well.
func (box *TaskIndexedBox) Put(object *TaskIndexed) (uint64, error) {
	return box.Box.Put(object)
}

// Insert synchronously inserts a single object. As opposed to Put, Insert will fail if given an ID that already exists.
// In case the Id is not specified, it would be assigned automatically (auto-increment).
// When inserting, the TaskIndexed.Id property on the passed object will be assigned the new ID as well.
func (box *TaskIndexedBox) Insert(object *TaskIndexed) (uint64, error) {
	return box.Box.Insert(object)
}

// Update synchronously updates a single object.
// As opposed to Put, Update will fail if an object with the same ID is not found in the database.
func (box *TaskIndexedBox) Update(object *TaskIndexed) error {
	return box.Box.Update(object)
}

// PutAsync asynchronously inserts/updates a single object.
// Deprecated: use box.Async().Put() instead
func (box *TaskIndexedBox) PutAsync(object *TaskIndexed) (uint64, error) {
	return box.Box.PutAsync(object)
}

// PutMany inserts multiple objects in single transaction.
// In case Ids are not set on the objects, they would be assigned automatically (auto-increment).
//
// Returns: IDs of the put objects (in the same order).
// When inserting, the TaskIndexed.Id property on the objects in the slice will be assigned the new IDs as well.
//
// Note: In case an error occurs during the transaction, some of the objects may already have the TaskIndexed.Id assigned
// even though the transaction has been rolled back and the objects are not stored under those IDs.
//
// Note: The slice may be empty or even nil; in both cases, an empty IDs slice and no error is returned.
func (box *TaskIndexedBox) PutMany(objects []*TaskIndexed) ([]uint64, error) {
	return box.Box.PutMany(objects)
}

// Get reads a single object.
//
// Returns nil (and no error) in case the object with the given ID doesn't exist.
func (box *TaskIndexedBox) Get(id uint64) (*TaskIndexed, error) {
	object, err := box.Box.Get(id)
	if err != nil {
		return nil, err
	} else if object == nil {
		return nil, nil
	}
	return object.(*TaskIndexed), nil
}

// GetMany reads multiple objects at once.
// If any of the objects doesn't exist, its position in the return slice is nil
func (box *TaskIndexedBox) GetMany(ids ...uint64) ([]*TaskIndexed, error) {
	objects, err := box.Box.GetMany(ids...)
	if err != nil {
		return nil, err
	}
	return objects.([]*TaskIndexed), nil
}

// GetManyExisting reads multiple objects at once, skipping those that do not exist.
func (box *TaskIndexedBox) GetManyExisting(ids ...uint64) ([]*TaskIndexed, error) {
	objects, err := box.Box.GetManyExisting(ids...)
	if err != nil {
		return nil, err
	}
	return objects.([]*TaskIndexed), nil
}

// GetAll reads all stored objects
func (box *TaskIndexedBox) GetAll() ([]*TaskIndexed, error) {
	objects, err := box.Box.GetAll()
	if err != nil {
		return nil, err
	}
	return objects.([]*TaskIndexed), nil
}

// Remove deletes a single object
func (box *TaskIndexedBox) Remove(object *TaskIndexed) error {
	return box.Box.Remove(object)
}

// RemoveMany deletes multiple objects at once.
// Returns the number of deleted object or error on failure.
// Note that this method will not fail if an object is not found (e.g. already removed).
// In case you need to strictly check whether all of the objects exist before removing them,
// you can execute multiple box.Contains() and box.Remove() inside a single write transaction.
func (box *TaskIndexedBox) RemoveMany(objects ...*TaskIndexed) (uint64, error) {
	var ids = make([]uint64, len(objects))
	for k, object := range objects {
		ids[k] = object.Id
	}
	return box.Box.RemoveIds(ids...)
}

// Creates a query with the given conditions. Use the fields of the TaskIndexed_ struct to create conditions.
// Keep the *TaskIndexedQuery if you intend to execute the query multiple times.
// Note: this function panics if you try to create illegal queries; e.g. use properties of an alien type.
// This is typically a programming error. Use QueryOrError instead if you want the explicit error check.
func (box *TaskIndexedBox) Query(conditions ...objectbox.Condition) *TaskIndexedQuery {
	return &TaskIndexedQuery{
		box.Box.Query(conditions...),
	}
}

// Creates a query with the given conditions. Use the fields of the TaskIndexed_ struct to create conditions.
// Keep the *TaskIndexedQuery if you intend to execute the query multiple times.
func (box *TaskIndexedBox) QueryOrError(conditions ...objectbox.Condition) (*TaskIndexedQuery, error) {
	if query, err := box.Box.QueryOrError(conditions...); err != nil {
		return nil, err
	} else {
		return &TaskIndexedQuery{query}, nil
	}
}

// Async provides access to the default Async Box for asynchronous operations. See TaskIndexedAsyncBox for more information.
func (box *TaskIndexedBox) Async() *TaskIndexedAsyncBox {
	return &TaskIndexedAsyncBox{AsyncBox: box.Box.Async()}
}

// TaskIndexedAsyncBox provides asynchronous operations on TaskIndexed objects.
//
// Asynchronous operations are executed on a separate internal thread for better performance.
//
// There are two main use cases:
//
// 1) "execute & forget:" you gain faster put/remove operations as you don't have to wait for the transaction to finish.
//
// 2) Many small transactions: if your write load is typically a lot of individual puts that happen in parallel,
// this will merge small transactions into bigger ones. This results in a significant gain in overall throughput.
//
// In situations with (extremely) high async load, an async method may be throttled (~1ms) or delayed up to 1 second.
// In the unlikely event that the object could still not be enqueued (full queue), an error will be returned.
//
// Note that async methods do not give you hard durability guarantees like the synchronous Box provides.
// There is a small time window in which the data may not have been committed durably yet.
type TaskIndexedAsyncBox struct {
	*objectbox.AsyncBox
}

// AsyncBoxForTaskIndexed creates a new async box with the given operation timeout in case an async queue is full.
// The returned struct must be freed explicitly using the Close() method.
// It's usually preferable to use TaskIndexedBox::Async() which takes care of resource management and doesn't require closing.
func AsyncBoxForTaskIndexed(ob *objectbox.ObjectBox, timeoutMs uint64) *TaskIndexedAsyncBox {
	var async, err = objectbox.NewAsyncBox(ob, 5, timeoutMs)
	if err != nil {
		panic("Could not create async box for entity ID 5: %s" + err.Error())
	}
	return &TaskIndexedAsyncBox{AsyncBox: async}
}

// Put inserts/updates a single object asynchronously.
// When inserting a new object, the Id property on the passed object will be assigned the new ID the entity would hold
// if the insert is ultimately successful. The newly assigned ID may not become valid if the insert fails.
func (asyncBox *TaskIndexedAsyncBox) Put(object *TaskIndexed) (uint64, error) {
	return asyncBox.AsyncBox.Put(object)
}

// Insert a single object asynchronously.
// The Id property on the passed object will be assigned the new ID the entity would hold if the insert is ultimately
// successful. The newly assigned ID may not become valid if the insert fails.
// Fails silently if an object with the same ID already exists (this error is not returned).
func (asyncBox *TaskIndexedAsyncBox) Insert(object *TaskIndexed) (id uint64, err error) {
	return asyncBox.AsyncBox.Insert(object)
}

// Update a single object asynchronously.
// The object must already exists or the update fails silently (without an error returned).
func (asyncBox *TaskIndexedAsyncBox) Update(object *TaskIndexed) error {
	return asyncBox.AsyncBox.Update(object)
}

// Remove deletes a single object asynchronously.
func (asyncBox *TaskIndexedAsyncBox) Remove(object *TaskIndexed) error {
	return asyncBox.AsyncBox.Remove(object)
}

// Query provides a way to search stored objects
//
// For example, you can find all TaskIndexed which Id is either 42 or 47:
//
// box.Query(TaskIndexed_.Id.In(42, 47)).Find()
type TaskIndexedQuery struct {
	*objectbox.Query
}

// Find returns all objects matching the query
func (query *TaskIndexedQuery) Find() ([]*TaskIndexed, error) {
	objects, err := query.Query.Find()
	if err != nil {
		return nil, err
	}
	return objects.([]*TaskIndexed), nil
}

// Offset defines the index of the first object to process (how many objects to skip)
func (query *TaskIndexedQuery) Offset(offset uint64) *TaskIndexedQuery {
	query.Query.Offset(offset)
	return query
}

// Limit sets the number of elements to process by the query
func (query *TaskIndexedQuery) Limit(limit uint64) *TaskIndexedQuery {
	query.Query.Limit(limit)
	return query
}
