/* ----------------------------------------
 * Origin  : GFI INFORMATIQUE 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 01/05/2015 : SCA : V2.1
 * Version : 14/04/2016 : SCA : V2.2 (PSWS-H2020)
 * ----------------------------------------
 */
package fr.tlse.irap.pt.client.controller.tools.common;

import java.util.Map;

import fr.tlse.irap.pt.client.controller.common.ISelectedItem;
import fr.tlse.irap.pt.client.controller.common.Item;
import fr.tlse.irap.pt.client.controller.common.SpaceElementCollection;
import fr.tlse.irap.spaceElement.SpaceElement;

public class StartEndItemBuilder {

	private static final String PLANETS = "Planets";
	private static final String PROBES = "Probes";
	private static final String COMETS = "Comets";
	private static final String SUN = "SUN";

	/**
	 * return the list of item on start planet.
	 */
	public static Item getStartingPlanetItem(Map<Item, ISelectedItem> map, final IStartEndController iStartEndController) {

		Item startingPlanetItem = new Item(PLANETS);

		for (final SpaceElement spaceElement : SpaceElementCollection.getPlanets()) {
			Item itemPlanet = new Item(spaceElement.getName());
			startingPlanetItem.add(itemPlanet);
			map.put(itemPlanet, new ISelectedItem() {
				@Override
				public void run() {
					iStartEndController.runStartPoint(spaceElement);
				}
			});
		}

		return startingPlanetItem;
	}
	
	/**
	 * return the list of item on start probe.
	 */
	public static Item getStartingProbeItem(Map<Item, ISelectedItem> map, final IStartEndController iStartEndController) {

		Item startingProbeItem = new Item(PROBES);
	
		for (final SpaceElement probe : SpaceElementCollection.getSpaceElementWrapper().getProbes()) {
			if (probe.isDefined()) {
				Item itemProbe = new Item(probe.getLongName());
				startingProbeItem.add(itemProbe);
	
				map.put(itemProbe, new ISelectedItem() {
					@Override
					public void run() {
						iStartEndController.runStartPoint(probe);
					}
				});
			}
		}

		return startingProbeItem;
	}

	/**
	 * return the list of item on start comets.
	 */
	public static Item getStartingCometItem(Map<Item, ISelectedItem> map, final IStartEndController iStartEndController) {

		Item startingCometItem = new Item(COMETS);

		for (final SpaceElement comet : SpaceElementCollection.getComets()) {
			Item itemComet = new Item(comet.getName());
			startingCometItem.add(itemComet);
			map.put(itemComet, new ISelectedItem() {
				@Override
				public void run() {
					iStartEndController.runStartPoint(comet);
				}
			});
		}

		return startingCometItem;
	}

	/**
	 * return end sun item.
	 */
	public static Item getStartingSunItem(Map<Item, ISelectedItem> map, final IStartEndController iStartEndController) {

		Item startingSunItem = new Item(SUN);

		map.put(startingSunItem, new ISelectedItem() {
			@Override
			public void run() {
				iStartEndController.runStartPoint(SpaceElementCollection.getSpaceElementWrapper().getSun());
			}
		});

		return startingSunItem;
	}

	/**
	 * return the list of item on end planet.
	 */
	public static Item getEndingPlanetItem(Map<Item, ISelectedItem> map, final IStartEndController iStartEndController) {

		Item endingPlanetItem = new Item(PLANETS);

		for (final SpaceElement planet : SpaceElementCollection.getPlanets()) {
			Item itemPlanet = new Item(planet.getName());
			endingPlanetItem.add(itemPlanet);
			map.put(itemPlanet, new ISelectedItem() {
				@Override
				public void run() {
					iStartEndController.runEndPoint(planet);
				}
			});
		}

		return endingPlanetItem;
	}
	
	/**
	 * return the list of item on end probe.
	 */
	public static Item getEndingProbeItem(Map<Item, ISelectedItem> map, final IStartEndController iStartEndController) {

		Item endingProbeItem = new Item(PROBES);
	
		for (final SpaceElement probe : SpaceElementCollection.getSpaceElementWrapper().getProbes()) {
			if (probe.isDefined()) {
				Item itemProbe = new Item(probe.getLongName());
				endingProbeItem.add(itemProbe);
	
				map.put(itemProbe, new ISelectedItem() {
					@Override
					public void run() {
						iStartEndController.runEndPoint(probe);
					}
				});
			}
		}

		return endingProbeItem;
	}

	/**
	 * return the list of item on end comet.
	 */
	public static Item getEndingCometItem(Map<Item, ISelectedItem> map, final IStartEndController iStartEndController) {

		Item endingCometItem = new Item(COMETS);

		for (final SpaceElement comet : SpaceElementCollection.getComets()) {
			Item itemComet = new Item(comet.getName());
			endingCometItem.add(itemComet);
			map.put(itemComet, new ISelectedItem() {
				@Override
				public void run() {
					iStartEndController.runEndPoint(comet);
				}
			});
		}

		return endingCometItem;
	}

	/**
	 * return end sun item.
	 */
	public static Item getEndingSunItem(Map<Item, ISelectedItem> map, final IStartEndController iStartEndController) {

		Item endingSunItem = new Item(SUN);

		map.put(endingSunItem, new ISelectedItem() {
			@Override
			public void run() {
				iStartEndController.runEndPoint(SpaceElementCollection.getSpaceElementWrapper().getSun());
			}
		});

		return endingSunItem;
	}

}