package at.vvo.omds.client.gui.api.calc;

import at.vvo.omds.helpers.GuiProdukt;
import at.vvo.omds.helpers.RDFHelper;
import at.vvo.omds.client.gui.api.SOAPConnector;
import at.vvo.omds.types.omds3.r2025_05.common.VerkaufsproduktType;
import at.vvo.omds.types.omds3.r2025_05.on2antrag.common.CalculateRequest;
import at.vvo.omds.types.omds3.r2025_05.on2antrag.common.CalculateResponse;
import jakarta.xml.bind.JAXBElement;
import javafx.scene.control.TreeView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.datatype.XMLGregorianCalendar;


public class CalculateRequestAuskunftService {

    Logger log = LoggerFactory.getLogger(CalculateRequestAuskunftService.class);

    private final SOAPConnector soapConnector;

    public CalculateRequestAuskunftService(SOAPConnector soapConnector) {
        this.soapConnector = soapConnector;
    }

    public CalculateResponse calculateAuskunft(TreeView<GuiProdukt> treeView, XMLGregorianCalendar vtBeg) throws Exception {

        String token = "<KEY>";
        JAXBElement<CalculateRequest> r = BuildCalculateRequestAuskunft.buildRequestFromTreeView(treeView, vtBeg);

        CalculateResponse response =
                soapConnector.calculateRequestAuskunft(
                        "http://localhost:9090/ws", r, token
                );
        log.info("Got Response As below ========= : ");
        log.info("Status : {}", response.getBerechnungsantwort().getVerkaufsprodukt().getBezeichnung());

        return response;
    }

    public VerkaufsproduktType calculateRDFAuskunft(TreeView<GuiProdukt> treeView, XMLGregorianCalendar vtBeg) throws Exception {

        String request = BuildCalculateRequestAuskunft.buildRDFRequestFromTreeView(treeView, vtBeg);

        RDFHelper rdfHelper = new RDFHelper();
        VerkaufsproduktType response = rdfHelper.getCalculateRDF(request);
        log.info("Got Response As below ========= : ");
        log.info("Status : {}", response.getBezeichnung());

        return response;
    }
}
