/* ----------------------------------------
 * Origin  : Akkodis
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 01/05/2015 : SCA : V2.1
 * Version : 19/07/2022 : LBE : V2.5
 * Redmine 7278: Build gaps in VPlot from sampling
 * Version : V2.12
 * DM-ID : redmine#11106 : 15/03/2025 : LBE : CDF SOLO speed data added from SOAR
 * ----------------------------------------
 */
package fr.tlse.irap.server.frontServices;

import java.util.Date;

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.vplot.DateRangeWrapper;
import fr.tlse.irap.vplot.IVPlot;
import fr.tlse.irap.vplot.SolarSpeedWrapper;

@WebService(endpointInterface = "fr.tlse.irap.vplot.IVPlot")
public class VPlotImpl implements IVPlot {
	private static final Logger logger = Logger.getLogger(VPlotImpl.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;
	}

	@Override
	public SolarSpeedWrapper fetchSolarSpeeds(Date t1, Date t2, String startName) {

		logger.info("fetchSolarSpeeds : t1=" + t1 + " t2=" + t2 + " startName=" + startName);
		SolarSpeedWrapper speedsWrapper = null;
		try {
                    if (startName.startsWith("SOLO")) {
			speedsWrapper = new SolarSpeedWrapper(cdfDAO.loadSolarSpeeds(t1, t2, startName));
                        speedsWrapper.setSampling(30);
                    } else {
			speedsWrapper = new SolarSpeedWrapper(asciiDAO.loadSolarSpeeds(t1, t2, startName));
                        speedsWrapper.setSampling(asciiDAO.loadSolarSpeedsSampling(startName));
                    }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return speedsWrapper;
	}

	@Override
	public DateRangeWrapper fetchDateRanges(Date t1, Date t2, String catalog, String startName, String catType) {
		logger.info("fetchDateRanges : startDate=" + t1 + " endDate=" + t2 + " catalog=" + catalog + " catType=" + catType);
		DateRangeWrapper dateRangesWrapper = null;
		try {
			dateRangesWrapper = new DateRangeWrapper(asciiDAO.loadDateRanges(t1, t2, catalog, startName, catType));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dateRangesWrapper;
	}
        

}
