package com.capgemini.reports.r22;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.capgemini.framework.teamcenter.policies.PolicyLocation;
import com.capgemini.reports.common.ServletMessageHelper;
import com.capgemini.reports.common.obtaindata.AbstractObtainDataFromPartRevision;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;

import javax.servlet.annotation.WebServlet;

/** This class receives demands form ajax client to initialize values id and revision for PartPV. */
@Slf4j
@WebServlet("/report_r22/obtainDataR22")
public class ObtainDataServletR22 extends AbstractObtainDataFromPartRevision {

    private static final long serialVersionUID = 6904998551660947706L;

    private static final String SUCCES_MESSAGE = "Données obtenues avec succès pour le rapport R22";

    @Override
    public JSONObject obtainDataFromPartRevision(final String partID, final String partRevisionID, final String partType,
                                                 final TcSession session) {
        log.info("Server received a request to obtain data for R22 report.");

        // TEST1 GOOD URL TEST : http://localhost:8080/kurt-web/dispatcherServlet?rd_id=REPORT_R22&dataValues=EidFrUN5hLofXA
        // TEST1 GOOD URL TEST with ALT: http://localhost:8080/kurt-web/dispatcherServlet?rd_id=REPORT_R22&dataValues=04XFrgrThLofXA
        // TEST 2 BAD UID http://localhost:8080/kurt-web/dispatcherServlet?rd_id=REPORT_R22&dataValues=EidFrUN5hLofXAVGFDFD
        // TEST 3 UID EMPTY http://localhost:8080/kurt-web/dispatcherServlet?rd_id=REPORT_R22&dataValues=

        // Compile the successfull JSON reponse containing all the elements required for the pickers
        JSONObject json = ServletMessageHelper.successMessage(SUCCES_MESSAGE);
        json.put("ObjectId", partID);
        json.put("ObjectRev", partRevisionID);
        json.put("ObjectType", partType);
        return json;
    }

    @Override
    protected PolicyLocation obtainLocation() {
        return PolicyLocation.make("R22_policy_light", "/xml/policies/r22report/R22_policy_light.xml");
    }


}
