/* ----------------------------------------
 * Origin  : GFI INFORMATIQUE 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 07/01/2022 : LBE : V2.4
 * DM-ID : Redmine#9098 : 07/01/2022 : creation
 * Version : 12/09/2023 : LBE : V2.8
 * DM-ID : Redmine#10629 : 12/09/2023 : SEP plot improvments
 * Version : 25/11/2024 : LBE : V2.11
 * DM-ID : Redmine#11104 : 25/11/2024 : VDA module added
 * ----------------------------------------
 */
package fr.tlse.irap.pt.client.controller.tools.plot;

import java.util.Date;
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 SpectroPlotModel {

    public static final int NB_TICS = 12;

    private static long deltaDays = 1;

    /**
     * Used to get file prefix on server
     */
    //private String source;
    private Date startDate = new Date();
    private Date endDate = new Date();
    private Date date;
    private boolean valid = true;

    public SpectroPlotModel() {
    }

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

    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 static Node createNodeLabel(String pName, Color c) {

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

    private static Node createNode(String pName, 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(pName);
        node.setUserData(null);

        return node;
    }

//    /**
//     * @return the source
//     */
//    public String getSource() {
//        return source;
//    }
//
//    /**
//     * @param source the source to set
//     */
//    public void setSource(String source) {
//        this.source = source;
//    }
}
