/* ----------------------------------------
 * Origin  : Akkodis 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 01/05/2015 : SCA : V2.1
 * Version : V2.12
 * DM-ID : Redmine#11103 : 25/03/2025 : LBE : Radio spectro interface added
 * ----------------------------------------
 */
package fr.tlse.irap.server.frontServices;

import java.util.Date;

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.apache.log4j.Logger;

import fr.tlse.irap.server.serviceDAO.IAsciiDAO;
import fr.tlse.irap.server.serviceDAO.ICdfDAO;
import fr.tlse.irap.spectro.ISpectro;
import fr.tlse.irap.spectro.Spectro;
import fr.tlse.irap.spectro.SpectroWrapper;
import fr.tlse.irap.tool.sep.Sep.Particle;
import java.util.List;

@WebService(endpointInterface = "fr.tlse.irap.spectro.ISpectro")
public class SpectroImpl implements ISpectro {
	private static final Logger logger = Logger.getLogger(SpectroImpl.class);
	private IAsciiDAO asciiDAO;
	private ICdfDAO cdfDAO;

	public IAsciiDAO getAsciiDAO() {
		return asciiDAO;
	}

	public void setAsciiDAO(IAsciiDAO asciiDAO) {
		this.asciiDAO = asciiDAO;
	}
	public ICdfDAO getCdfDAO() {
		return cdfDAO;
	}

	public void setCdfDAO(ICdfDAO cdfDAO) {
		this.cdfDAO = cdfDAO;
	}

	@WebMethod
	public SpectroWrapper fetchSpectro(Date t1, Date t2, String startName, Particle particle) {

		logger.info("fetchSpectro : t1=" + t1 + " t2=" + t2 + " startName=" + startName);
		SpectroWrapper spectroWrapper = new SpectroWrapper();
		try {
                    List<Object> lSpectro = asciiDAO.loadSEPFlux(t1, t2, startName, particle);
                    if(lSpectro!=null && lSpectro.size()==2) {
                        spectroWrapper = new SpectroWrapper((List<Float[]>)lSpectro.get(0),(List<Spectro>)lSpectro.get(1));
                    }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return spectroWrapper;
	}

	@WebMethod
	public SpectroWrapper fetchRadioSpectro(Date t1, Date t2, String startName) {

		logger.info("fetchSpectro : t1=" + t1 + " t2=" + t2 + " startName=" + startName);
		SpectroWrapper spectroWrapper = new SpectroWrapper();
		try {
                    List<Object> lSpectro = cdfDAO.loadSpectro(t1, t2, startName);
                    if(lSpectro!=null && lSpectro.size()==2) {
                        spectroWrapper = new SpectroWrapper((List<Float[]>)lSpectro.get(0),(List<Spectro>)lSpectro.get(1));
                    }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return spectroWrapper;
	}
        
        
}
