/*
 * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
 *
 * This file is part of PeerfactSim.KOM.
 * 
 * PeerfactSim.KOM 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
 * any later version.
 * 
 * PeerfactSim.KOM 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 PeerfactSim.KOM.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package de.tud.kom.p2psim.impl.topology.views.fiveg.models;

import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.impl.topology.views.FiveGTopologyView;
import de.tud.kom.p2psim.impl.topology.views.fiveg.ModelBasedSegmentDatabase;
import de.tud.kom.p2psim.impl.topology.views.fiveg.utils.Direction;
import de.tud.kom.p2psim.impl.topology.views.fiveg.utils.Graph;
import de.tud.kom.p2psim.impl.topology.views.fiveg.utils.ParameterType;

/**
 * Abstract base model for the {@link FiveGTopologyView} when using the {@link ModelBasedSegmentDatabase}.
 * 
 * @author Nils
 * @version 1.0, 05.03.2017
 */
public abstract class AbstractModel {
	
	// Storage 
	private int segmentID = -1;
	private ParameterType type;
	private Direction dir = Direction.BOTH;
	
	// Is debug enabled for this model
	private boolean debug = false;
	
	public void setSegmentID(int segmentid) {
		assert segmentid > 0;
		this.segmentID = segmentid;
	}

	public int getSegmentID() {
		return this.segmentID;
	}

	/**
	 * Set the parameter type {@link ParameterType}
	 * @param param
	 */
	public void setParameterType(String param) {
		param = param.toUpperCase();
		// Check if type is valid
		try {
			this.type = ParameterType.valueOf(param);
		} catch (IllegalArgumentException e) {
			throw new ConfigurationException(
					"The Parameter " + param + " is unknown. Please select one of "
							+ ParameterType.printTypes());
		}
		if(this.type == null) {
			throw new ConfigurationException(
					"The Parameter " + param + " is unknown. Please select one of "
							+ ParameterType.printTypes());
		}
	}
	
	public ParameterType getParameterType() {
		return type;
	}
	
	/**
	 * Set the direction of model {@link Direction}
	 * @param param
	 */
	public void setDirection(String param) {
		param = param.toUpperCase();
		try {
			this.dir = Direction.valueOf(param);
		} catch (IllegalArgumentException e) {
			throw new ConfigurationException(
					"Direction " + param + " is unknown. Please select one of "
							+ Direction.printTypes());
		}
		if(this.type == null) {
			throw new ConfigurationException(
					"Direction " + param + " is unknown. Please select one of "
							+ Direction.printTypes());
		}
	}
	
	public Direction getDirection() {
		return dir;
	}
	
	/**
	 * Enable debugging - visualization of the model set in the config.
	 * 
	 * @param debug
	 */
	public void setDebug(boolean debug) {
		this.debug = debug;
	}
	
	public boolean getDebug() {
		return this.debug;
	}

	public abstract long getLong(int users);

	public abstract double getDouble(int users);
	
	/**
	 * Debug this model
	 */
	public void debug() {
		Graph test = new Graph();
		test.setModel(this);
	}
}
