package eu.dnetlib.espas.api.sos;

import eu.dnetlib.espas.api.exception.OwsException;

import java.io.PrintWriter;
import java.util.Map;

public class SOSService {
    private Sos sos;

    /*
            getResultTemplate
        -----------------
        1. collect all data providers
        2. for each provider
            3. send a getResultTemplate request to collect metadata such as fields, token and block separators
            4. create a ResultTemplate object with the collected metadata
            5. build the answer with the collected fields and the token and block separators
            from the API's configuration file
        6. merge the answer with headers and send back to user


        getResult
        ---------
        1. collect all data providers
        2. for each provider
            3. send a getResultTemplate request to collect metadata such as token and block separators
            4. send the same request and parse results
            5. collect results to a common structure
        6. build answer with headers, token and block separators
        7. send answer back to user
     */

    void getResultTemplate(PrintWriter pw, Map<String, String> parameters) throws OwsException {
        pw.println(sos.getResultTemplate(parameters));
    }

    void getResult(PrintWriter pw, Map<String, String> parameters) throws OwsException {
        String result = sos.getResult(parameters);

//        pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
//        pw.println("<sos:GetResultResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
//                " xmlns:swe=\"http://www.opengis.net/swe/2.0\"" +
//                " xmlns:swes=\"http://www.opengis.net/swes/2.0\"" +
//                " xmlns:ows=\"http://www.opengis.net/ows/1.1\"" +
//                " xmlns:sos=\"http://www.opengis.net/sos/2.0\"" +
//                " xmlns:fes=\"http://www.opengis.net/fes/2.0\"" +
//                " xmlns:gml=\"http://www.opengis.net/gml/3.2\"" +
//                " xmlns:ogc=\"http://www.opengis.net/ogc\"" +
//                " xmlns:om=\"http://www.opengis.net/om/2.0\"" +
//                " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" +
//                " xsi:schemaLocation=\"http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sos.xsd\">");
//        pw.println("<sos:resultValues>");
            pw.println(result);
//        pw.println("</sos:resultValues>");
//        pw.println("</sos:GetResultResponse>");
    }

    public Sos getSos() {
        return sos;
    }

    public void setSos(Sos sos) {
        this.sos = sos;
    }
}