package de.lazyzero.kkMulticopterFlashTool.utils.EEprom;

import java.util.LinkedHashMap;

public abstract class EEpromDataItem {
	public static int BOOLEAN = 0;
	public static int INTEGER = 1;
	
	protected String type = "";
	protected int startAddress = 0;
	protected int length = 1;
	protected String label = "";
	protected int dataType = 0;
	protected Short[] value;
	protected LinkedHashMap<Short, String> dataMapping;
	
	public EEpromDataItem (EEprom eeprom, String type, int startAddress, int length, int dataType, LinkedHashMap<Short, String> dataMapping, String label) {
			setType(type);
			setStartAddress(startAddress);
			setLength(length);
			setDataType(dataType);
			setDataMapping(dataMapping);
			setLabel(label);
			setValues(eeprom);
		}
	
	
	protected void setValues(EEprom eeprom) {
		value = eeprom.getCells(startAddress, length);
	}

	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public int getStartAddress() {
		return startAddress;
	}
	public void setStartAddress(int startAddress) {
		this.startAddress = startAddress;
	}
	public int getLength() {
		return length;
	}
	public void setLength(int length) {
		this.length = length;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public int getDataType() {
		return dataType;
	}
	public void setDataType(int dataType) {
		this.dataType = dataType;
	}

	protected void setDataMapping(LinkedHashMap<Short, String> dataMapping) {
		this.dataMapping = dataMapping;
	}
	
	public EEprom updateEEprom(EEprom eeprom) {
		for (int i = 0; i < value.length; i++) {
			eeprom.setCell(i+startAddress, value[i]);
		}
		eeprom.writeRawEEprom();
		return eeprom;
	}

}
