/* ----------------------------------------
 * Origin  : GFI INFORMATIQUE 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 17/11/2017 : SCA : V2.2.2
 *  Creation
 * Version : 05/05/2021 : LBE
 * DM-ID : Redmine#7043 : 05/05/2021 : Fermi-LAT units corrected
 * Version : 28/01/2022 : LBE
 * FA-ID : Redmine#9169 : 28/01/2022 : GOES14=>GOES
 * ----------------------------------------
 */
package fr.tlse.irap.pt.client.controller.tools.plot;

import java.util.Date;

import fr.tlse.irap.pt.client.controller.common.FlareCollection;
import fr.tlse.irap.flare.Flare.FlareType;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.QuadCurveTo;

public class FluxPlotModel {

	public static final int NB_TICS = 12;
	public static FlareType[] fc = FlareType.values();
	
	private Date startDate = new Date();
	private Date endDate = new Date();
	private Date date;
	private double flux;
	private boolean valid;
	
	public enum FluxType {
		EUV("Extrem UV"),
		SOFT_XRAYS("Soft X-Rays"),
		HARD_XRAYS("Hard X-Rays"),
		GAMMA("Gamma");
		
		private String name;

		FluxType(String name) {
			this.setName(name);
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
	}

	public enum FluxMeasure {
		GOES14_05_40A("GOES 0.5-4.0 A", "GOES_XRAYS_0.05_0.40"),
		GOES14_10_80A("GOES 1.0-8.0 A", "GOES_XRAYS_0.10_0.80"),
		HARDXRAYS("HARD X-RAYS", "HARD_XRAYS"),
		GAMMA("Fermi-LAT", "GAMMA"),
		EUV("Extrem UV", "EUV");
		
		private String name;
		private String dirName;

		FluxMeasure(String name, String dirName) {
			this.setName(name);
			this.setDirName(dirName);
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getDirName() {
			return dirName;
		}
		public void setDirName(String dirName) {
			this.dirName = dirName;
		}
	}

	public FluxPlotModel() {
	}
	
    /**
     * update dates 
     */
	public void setDates(Date selectedDate) {
		date = selectedDate;
		startDate.setTime(date.getTime() - FlareCollection.DELTA_DAYS * 86400000);
		endDate.setTime(date.getTime() + FlareCollection.DELTA_DAYS * 86400000);
	}

	public Date getStartDate() {
		return startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public Date getDate() {
		return date;
	}

	public long getT1() {
		return startDate.getTime();
	}

	public long getT2() {
		return endDate.getTime();
	}

	public long getTime() {
		return date.getTime();
	}

	public void setTime(long time) {
		// create a new date, so that property will be invalidated
		date = new Date();
		date.setTime(time);
	}

	public boolean isValid() {
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

	public double getFlux() {
		return flux;
	}

	public void setFlux(double flux) {
		this.flux = flux;
	}

	
	public static Node createNodeLabel (FluxMeasure fMeasure, Color c) {

		Node node = createNode(fMeasure, c);
		if (node != null) {
			Label label = new Label(fMeasure.getName(), node);
			label.setId(fMeasure.name());
			return label;
		} 
		else {
			return null;
		}
	}

	private static Node createNode(FluxMeasure fMeasure, Color c) {
		Path node = new Path();
		
		MoveTo moveTo = new MoveTo(0, 0);
		node.getElements().add(moveTo);
		QuadCurveTo quadCurveTo = new QuadCurveTo(15, 0, 15, 0);
		node.getElements().add(quadCurveTo);
		
		node.setFill(c);
		node.setStroke(c);
		node.setId(fMeasure.name());
		node.setUserData(null);
		
		return node;
	}

}
