/*
 * 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.component;

import java.util.Set;

import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.energy.UAVReplacementCharger;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.communication.BaseToUAVInterface;
import de.tudarmstadt.maki.simonstrator.api.uavsupport.communication.UAVToBaseInterface;



public class BaseTopologyComponent extends AbstractTopologyComponent {

	private OverlayComponent baseOverlayComponent;
	private UAVReplacementCharger charger;
	private BaseToUAVInterface controllerInterface;
	
	public BaseTopologyComponent(SimHost host, Topology topology,
			MovementModel movementModel, PlacementModel placementModel,
			boolean registerAsInformationProviderInSiS) {
		super(host, topology, movementModel, placementModel,
				registerAsInformationProviderInSiS);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public void initialize() {		
		super.initialize();
		
		try {
			charger = getHost().getComponent(UAVReplacementCharger.class);
		} catch (ComponentNotAvailableException e) {
			throw new AssertionError("Unable to retrieve Replacement Charger for Base!");
		}
	}

	@Override
	public double getMinMovementSpeed() {
		throw new UnsupportedOperationException();
	}

	@Override
	public double getMaxMovementSpeed() {
		throw new UnsupportedOperationException();
	}

	@Override
	public double getMovementSpeed() {
		throw new UnsupportedOperationException();
	}

	@Override
	public void setMovementSpeed(double speed) {
		throw new UnsupportedOperationException();
	}

	@Override
	public Set<IAttractionPoint> getAllAttractionPoints() {
		throw new UnsupportedOperationException();
	}
	
	@Override
	public void setTargetAttractionPoint(IAttractionPoint targetAttractionPoint) {
		throw new UnsupportedOperationException();
	}

	@Override
	public IAttractionPoint getCurrentTargetAttractionPoint() {
		throw new UnsupportedOperationException();
	}

	public void setOverlayComponent(OverlayComponent component) {
		this.baseOverlayComponent = component;
	}

	public OverlayComponent  getBaseComponent() {
		return baseOverlayComponent;
	}
	
	public UAVReplacementCharger getCharger() {
		return charger;
	}
	
	public void setControllerInterface(BaseToUAVInterface controllerInterface) {
		this.controllerInterface = controllerInterface;
	}
	
	public void connectUAVToBase(UAVToBaseInterface uav) {
		this.controllerInterface.connectUAVtoBase(uav);
	}
	
	public void disconnectUAVFromBase(UAVToBaseInterface uav) {
		this.controllerInterface.disconnectUAV(uav);
	}
	
	public static class Factory implements TopologyComponentFactory {

		@Override
		public TopologyComponent createTopologyComponent(SimHost host,
				Topology topology, MovementModel movementModel,
				PlacementModel placementModel,
				boolean registerAsInformationProviderInSiS) {
			return new BaseTopologyComponent(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
		}
		
	}
}
