/* ----------------------------------------
 * Origin  : GFI INFORMATIQUE 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 01/05/2015 : SCA : V2.1
 * Version : 26/10/2017 : SCA : V2.2.1
 *  Redmine 5501
 * Version : 25/11/2022 : LBE : V2.6
 * DM-ID : Redmine#7316 : new AMDA parameters
 * ----------------------------------------
 */
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.tools.externalLinks.AmdaModel.Observer;
import fr.tlse.irap.pt.client.controller.tools.externalLinks.AmdaModel.PlotParam;

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

	private static Map<String, List<PlotParam>> probePlotParam = new HashMap<String, List<PlotParam>>();

	/**
	 * Init spacecraft instruments
	 */
	private static void initProbePlotParam() {
		/* Add instruments of the observable probes */
		if (probePlotParam.isEmpty()) {
			List<PlotParam> ppProbe = new ArrayList<PlotParam>();
			ppProbe.add(PlotParam.PPX);
			List<PlotParam> ppSTEREO = new ArrayList<PlotParam>();
			ppSTEREO.add(PlotParam.PPS);
			ppSTEREO.add(PlotParam.PP_ST_EP);
			List<PlotParam> pp;
			for (Observer obs : Observer.values()) {
				switch (obs) {
					case GEOMAG:
						pp = new ArrayList<PlotParam>();
						pp.add(PlotParam.PPG);
						break;
					case MEX:
						pp = new ArrayList<PlotParam>();
						pp.add(PlotParam.PPM);
						break;
					case STEREO_A:
					case STEREO_B:
						pp = ppSTEREO;
						break;
					case VEX:
						pp = new ArrayList<PlotParam>();
						pp.add(PlotParam.PPV);
						break;
					case WIND:
						pp = new ArrayList<PlotParam>();
						pp.add(PlotParam.PPW);
						break;
					case SOLO:
						pp = new ArrayList<PlotParam>();
                                                //pp.add(PlotParam.PPX);
                                                pp.add(PlotParam.PP_SO_MAG);
						pp.add(PlotParam.PP_SO_EP);
						break;
					case PSP:
						pp = new ArrayList<PlotParam>();
                                                //pp.add(PlotParam.PPX);
						pp.add(PlotParam.PP_PSP_EP);
						break;
					case ROSETTA:
						pp = new ArrayList<PlotParam>();
                                                //pp.add(PlotParam.PPX);
						pp.add(PlotParam.PP_ROSETTA);
						break;
					case JUNO:
						pp = new ArrayList<PlotParam>();
                                                //pp.add(PlotParam.PPX);
						pp.add(PlotParam.PP_JUNO);
                                                //pp.add(PlotParam.PP_JUNO_JUPITER_ORBIT);
						break;
					case CASSINI:
						pp = new ArrayList<PlotParam>();
                                                //pp.add(PlotParam.PPX);
						pp.add(PlotParam.PP_CASSINI);
						break;
					case MGS:
						pp = new ArrayList<PlotParam>();
                                                //pp.add(PlotParam.PPX);
						pp.add(PlotParam.PP_MGS);
						break;
					case MESSENGER:
						pp = new ArrayList<PlotParam>();
                                                //pp.add(PlotParam.PPX);
						pp.add(PlotParam.PP_MESSENGER);
						break;
					default:
						pp = ppProbe;
						break;
				}
				probePlotParam.put(obs.name(), pp);
			}
		}
	}

	/**
	 * Get list of parameters of instrument
	 */
	public static List<PlotParam> getPlotParam(Observer observer) {
		if (probePlotParam.isEmpty()) {
			initProbePlotParam();
		}
		return probePlotParam.get(observer.name());
	}

	/**
	 * build items of Choose menu 
	 */
	public static Item getObserverItem(final Observer observer, Map<Item, ISelectedItem> map, final IAmda amdaMenu) {
		Item obsItem = new Item(observer.getName());
		for (final PlotParam plotParam : getPlotParam(observer)) {
			Item ppItem = new Item(plotParam.getLongList());
			map.put(ppItem, new ISelectedItem() {
				@Override
				public void run() {
					amdaMenu.runChoose(observer, plotParam);
				}
			});
			obsItem.add(ppItem);
		}
		return obsItem;
	}

}
