/**************************************************************************************
 *
 *     Project:    kvmstoreserver
 *     File name:  dataModel.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 (
	"fmt"
)

//*****************************************************************************
//*
//*      Structure: DataModel
//*
//*****************************************************************************

// DataModel Contains the revision number, the metadata, and the JSON document
// stored in a mapped interface structure
type DataModel struct {
	RevNbr     int                    `json:"rev_nbr"`
	MetaHeader *MetaData              `json:"meta_header"`
	Data       map[string]interface{} `json:"data"`
}

// Search picks up a string and views the identifier in the map
func (slf *DataModel) Search(s string) (interface{}, error) {

	// If a key exists but is NIL, this information will also be returned as Go
	// NIL. Otherwise an ERROR
	for mKeyName := range slf.Data {
		if s == mKeyName {
			return slf.Data[s], nil
		}
	}

	return nil, fmt.Errorf("There is no element in the values ​​map with this name -> %v",
		s)
}
