/* ----------------------------------------
 * Origin  : GFI INFORMATIQUE 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 01/05/2015 : SCA : V2.1
 * Version : 15/09/2016 : SCA : V2.2.2
 * 	Drop HI1, HI2 cameras from menu 
 * ----------------------------------------
 */
package fr.tlse.irap.pt.client.controller.tools.externalLinks;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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.pt.client.controller.tools.externalLinks.MedocModel.Observer;
import fr.tlse.irap.pt.client.controller.tools.externalLinks.MedocModel.WaveLength;
import fr.tlse.irap.spaceElement.Camera;

/**
 * 
 * JMap contextual menu builder
 * 
 */
public class MedocItemBuilder {

	private static Map<String, List<WaveLength>> cameraWaveLengths = new HashMap<String, List<WaveLength>>();
	
	/**
	 * Init spacecraft cameras
	 */
	private static void initCameraWaveLengths() {
		List<WaveLength> wlAIA = new ArrayList<WaveLength>();
		wlAIA.add(WaveLength.A94);
		wlAIA.add(WaveLength.A131);
		wlAIA.add(WaveLength.A171);
		wlAIA.add(WaveLength.A193);
		wlAIA.add(WaveLength.A211);
		wlAIA.add(WaveLength.A304);
		wlAIA.add(WaveLength.A335);
		wlAIA.add(WaveLength.A1600);
		wlAIA.add(WaveLength.A1700);
		wlAIA.add(WaveLength.A4500);
		cameraWaveLengths.put("AIA", wlAIA);

		List<WaveLength> wlEUVI = new ArrayList<WaveLength>();
		wlEUVI.add(WaveLength.A171);
		wlEUVI.add(WaveLength.A195);
		wlEUVI.add(WaveLength.A284);
		wlEUVI.add(WaveLength.A304);
		cameraWaveLengths.put("EUVI", wlEUVI);

		List<WaveLength> wlCOR1 = new ArrayList<WaveLength>();
		wlCOR1.add(WaveLength.WL);
		cameraWaveLengths.put("COR1", wlCOR1);
	
		List<WaveLength> wlCOR2 = new ArrayList<WaveLength>();
		wlCOR2.add(WaveLength.WL);
		cameraWaveLengths.put("COR2", wlCOR2);

		List<WaveLength> wlEIT = new ArrayList<WaveLength>();
		wlEIT.add(WaveLength.A171);
		wlEIT.add(WaveLength.A195);
		wlEIT.add(WaveLength.A284);
		wlEIT.add(WaveLength.A304);
		cameraWaveLengths.put("EIT", wlEIT);

		List<WaveLength> wlC2 = new ArrayList<WaveLength>();
		wlC2.add(WaveLength.WL);
		cameraWaveLengths.put("C2", wlC2);

		List<WaveLength> wlC3 = new ArrayList<WaveLength>();
		wlC3.add(WaveLength.WL);
		cameraWaveLengths.put("C3", wlC3);
	}

	/**
	 * Get list of wave lenghts of a camera
	 */
	public static List<WaveLength> getWaveLengths(Camera c) {
		if (cameraWaveLengths.isEmpty()) {
			initCameraWaveLengths();
		}
		//return cameraWaveLengths.get(c.getDetector());
		return cameraWaveLengths.get(c.getName());
	}

	/**
	 * build items of Choose menu 
	 */
	public static Item getObserverItem(final Observer observer, Map<Item, ISelectedItem> map, final IMedoc medocMenu) {
		Item obsItem = new Item(observer.getName());
                //System.out.println("************************* Getting cameras for "+observer.getName());
		for (final Camera camera : SpaceElementCollection.getCameras(observer.getName())) {
			//Item instrItem = new Item(camera.getDetector());
                //System.out.println("***************************** found "+camera.getName());
			Item instrItem = new Item(camera.getName());
			if (getWaveLengths(camera) != null) {
				for (final WaveLength waveLength : getWaveLengths(camera)) {
					Item wlItem = new Item(waveLength.getName());
					map.put(wlItem, new ISelectedItem() {
						@Override
						public void run() {
							medocMenu.runChoose(observer, camera, waveLength);
						}
					});
					instrItem.add(wlItem);
				}
				obsItem.add(instrItem);
			}
		}
		return obsItem;
	}
}
