/**************************************************************************************
 *
 *     Project:    kvmstoreserver
 *     File name:  interfaces.go
 *     Version:    1.0.0
 *     Date:       2018-01-14
 *
 *     Autor:      Bogdanovic Theodor
 *     Contact:    t.bogdanovic@hotmail.com
 *
 *     License:    GPLv3
 *
 **************************************************************************************/
/**************************************************************************************
 * Copyright 2018 Bogdanovic Theodor
 *
 * This file is part of kvmstoreserver.
 *
 * kvmstoreserver is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * kvmstoreserver is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with kvmstoreserver.  If not, see <http://www.gnu.org/licenses/>.
 **************************************************************************************/
/**************************************************************************************
 *  Further explanations:  This source code is under the license specified by the
 *                         Autor above. Core components or other packages are still
 *                         in source code form, under the license specified by the
 *                         respective author.
 **************************************************************************************/

package bTreeHandling

import knh "kvmstoreserver_utils/keyNameHandling"

// IBtreeController includes the logic that is needed from the
// outside to use the tree
type IBtreeController interface {

	// Insert a dataModel in the tree. the position (nodeID) is
	// read from the key context.
	Insert(nodeCtx knh.IHandelWithIds, data *DataModel) (int, error)

	// InsertContainer a complete container in the Tree.
	// Is it only used by the node loader -> stage0_ext1
	InsertContainer(ct IHandelWithNodes)

	// Member Checks if a node exists with the passed key context in the tree.
	Member(nodeCtx knh.IHandelWithIds) error

	// Get returns an interface to the node container.
	// This can be used to access data in the node contianer
	Get(nodeCtx knh.IHandelWithIds) IHandelWithNodes

	// Del deletes a complete node Container from the tree
	Del(nodeCtx knh.IHandelWithIds) error

	// GetBtreeStruct returns the structure of the tree mapped
	// into a slice. The slice is also converted into a JSON document
	GetBtreeStruct() []byte
}

// IHandelWithNodes includes the logic that is needed to work
// with node containers. The caller always keeps this interface,
// never the non-exported node container structure
type IHandelWithNodes interface {

	// GetID returns the node container ID
	GetID() int

	// GetOrigKeyName returns the origianl Key name
	GetOrigKeyName() string

	// GetModelOrDefault provides the required revision of the
	// DataModel. Default is the last and most recent
	GetModelOrDefault(revNbr *int) (*DataModel, error)
}
