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

import at.vvo.omds.helpers.Plausi;
import at.vvo.omds.helpers.RDFHelper;
import at.vvo.omds.client.gui.api.SOAPConnector;
import at.vvo.omds.types.omds3.r2025_05.common.APrioriVerkaufsproduktType;
import at.vvo.omds.types.omds3.r2025_05.common.ProductsRequest;
import at.vvo.omds.types.omds3.r2025_05.common.ProductsResponse;
import jakarta.xml.bind.JAXBElement;
import javafx.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.datatype.XMLGregorianCalendar;
import java.util.List;


public class AprioriAuskunftService {

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

    private final SOAPConnector soapConnector;

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

    public ProductsResponse aprioriAuskunft(XMLGregorianCalendar stichtag, String vuNr) throws Exception {

        String token = "<KEY>";
        JAXBElement<ProductsRequest> r = BuildProductsRequest.aprioriRequest(stichtag, vuNr);

        ProductsResponse response =
                soapConnector.aprioriAuskunft(
                        "http://localhost:9090/ws", r, token
                );
        log.info("Got Response As below ========= : ");
        log.info("Status : {}", response.getVerkaufsprodukt().getFirst().getName());

        return response;
    }

    public Pair<List<APrioriVerkaufsproduktType>, List<Plausi>> aprioriRDFAuskunft(XMLGregorianCalendar stichtag, String vuNr) throws Exception {
        JAXBElement<ProductsRequest> r = BuildProductsRequest.aprioriRequest(stichtag, vuNr);

        RDFHelper rdfHelper = new RDFHelper();
        Pair<List<APrioriVerkaufsproduktType>, List<Plausi>> response = rdfHelper.getAprioriRDF(r);

        log.info("Got Response As below ========= : ");
        log.info("Status : {}", response.getKey().getFirst().getName());

        return response;
    }
}
