/* ----------------------------------------
 * Origin  : GFI INFORMATIQUE 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 01/05/2015 : SCA : V2.1
 * Version : 24/03/2016 : SCA : V2.2 (PSWS-H2020)
 *  Swap STEREO-A / STEREO-B FOV after 14/07/2015
 * VERSION : 04/06/2024 : V2.10
 * Redmine#11605 : 04/06/2024 : second swap date added for stereo
 * ----------------------------------------
 */
package fr.tlse.irap.spaceElement;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Probe extends SpaceElement {

    private static final long serialVersionUID = 1L;

    private boolean observer;
    //private static Date swapDate;
    private Date inServiceDate;

    public Probe() {
        super();
    }

    public Probe(String name) {
        super(name);
    }

    /**
     * Specific constructor
     *
     * @param name
     * @param id
     * @param size
     * @param color
     * @param step
     * @param dataSize
     * @param isInner
     * @param isObserver
     */
    public Probe(String name, String longName, int id, int size, String color, int step, int dataSize, boolean isObserver, String inServiceDate) {
        super(name, longName, id, size, color, step, dataSize);
        setObserver(isObserver);
        setInServiceDate(inServiceDate);
    }

    public Probe(String name, String longName, int id, int size, String color, int step, int dataSize, boolean isObserver) {
        this(name, longName, id, size, color, step, dataSize, isObserver, null);
    }

    public Probe(String name, int id, int size, String color, int step, int dataSize, boolean isObserver) {
        this(name, name, id, size, color, step, dataSize, isObserver);
    }

    public boolean isObserver() {
        return observer;
    }

    public void setObserver(boolean observer) {
        this.observer = observer;
    }

    public Date getInServiceDate() {
        return inServiceDate;
    }

    public void setInServiceDate(String date) {
        if (date != null) {
            try {
                inServiceDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(date);
                System.out.println("inServiceDate of " + getName() + " is " + inServiceDate);

            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }

    public void setInServiceDate(Date date) {
        inServiceDate = date;
    }

//    /**
//     * Get STEREO swap date when STEREO-A and STEREO-B cross over the sun and
//     * change their attitude direction
//     *
//     * @return 2015-07-14
//     */
//    public static Date getStereoSwapDate() {
//        if (swapDate == null) {
//            swapDate = new Date();
//            try {
//                swapDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse("2015-07-14T00:00:00");
//            } catch (ParseException e) {
//                e.printStackTrace();
//            }
//        }
//        return swapDate;
//    }

    
    /**
     * Get the angle direction (forward or backward) of the probe FOV according
     * to date
     *
     * @param pDate
     * @return
     */
    public boolean isBackward(Date pDate) {
        return isBackward(getName(), pDate);
    }
    
    /**
     * Get the angle direction (forward or backward) of the probe FOV according
     * to date
     *
     * @param pDate
     * @return
     */
    public static boolean isBackward(String pProbeName, Date pDate) {
        if (pProbeName.equals("PSP")) {
            return true;
        } else if (pProbeName.startsWith("STEREO")) {
            try {
                //STEREO case
                Date swapDate1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse("2015-07-14T00:00:00");
                Date swapDate2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse("2023-08-15T00:00:00");
                if (pDate.before(swapDate1) || pDate.after(swapDate2)) {
                    if (pProbeName.equals("STEREO-B")) {
                        return true;
                    }
                } else if (pProbeName.equals("STEREO-A")) {
                    return true;
                }
            } catch (ParseException ex) {
                Logger.getLogger(Probe.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return false;
    }

}
