package com.capgemini.reports.r11;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

import com.capgemini.reports.common.AbstractSubmitServlet;
import com.capgemini.reports.definition.r11report.ExecutionR11;
import com.capgemini.reports.reports.parameters.EffectivityDate;
import com.capgemini.reports.reports.parameters.Generics;
import com.capgemini.reports.reports.parameters.MonoMulti;
import com.capgemini.reports.reports.parameters.ProductUnit;

/**
 * This class receives demands to perform a R11 report.<br>
 * It prepares the data and creates the appropriate {@link ExecutionR11} instance that will carry out the job.
 */
@WebServlet("/report_r11/submit")
public class SubmitServletR11 extends AbstractSubmitServlet<ExecutionR11> {

    private static final long serialVersionUID = -4474495288200901492L;

    @Override
    public ExecutionR11 prepareReport(final HttpServletRequest request) {
        // Obtaining report parameters
        String productID = request.getParameter("product_id");
        String unitStr = request.getParameter("unit");
        String genericId = request.getParameter("generic");
        String effectivityStr = request.getParameter("datepicker");
        String monoMultiStr = request.getParameter("mono_multi");

        // Checking product-unit relationship
        ProductUnit productUnit = new ProductUnit(productID, unitStr);
        Generics generic = new Generics(productUnit, genericId, null);

        // Checking mono-multi
        MonoMulti monoMulti = MonoMulti.build(monoMultiStr);

        // Checking effectivity
        EffectivityDate effectivity = new EffectivityDate(effectivityStr);

        return new ExecutionR11(generic, monoMulti, effectivity);
    }
}
