package org.openlmis.report.controller;

import lombok.NoArgsConstructor;
import org.openlmis.report.response.OpenLmisResponse;
import org.openlmis.report.service.lookup.DashboardLookupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * User: Issa
 * Date: 2/18/14
 * Time: 5:18 PM
 */
@Controller
@NoArgsConstructor
@RequestMapping(value = "/dashboard")
public class DashboardController extends BaseController {

    @Autowired
    DashboardLookupService lookupService;

    @RequestMapping(value = "/itemFillRate", method = GET, headers = BaseController.ACCEPT_JSON)
    public ResponseEntity<OpenLmisResponse>  getItemFillRate(@RequestParam("geographicZoneId") Long geographicZoneId,
                                                             @RequestParam("periodId") Long periodId,
                                                             @RequestParam("facilityId") Long facilityId,
                                                             @RequestParam("programId") Long programId,
                                                             @RequestParam("productListId")List<Long> productListId){
      return OpenLmisResponse.response("itemFillRate", this.lookupService.getItemFillRate(geographicZoneId, periodId, facilityId, programId, productListId));
    }

    @RequestMapping(value = "/orderFillRate", method = GET, headers = BaseController.ACCEPT_JSON)
    public ResponseEntity<OpenLmisResponse>  getOrderFillRate(@RequestParam("geographicZoneId") Long geographicZoneId,
                                                              @RequestParam("periodId") Long periodId,
                                                              @RequestParam("facilityId") Long facilityId,
                                                              @RequestParam("programId") Long programId){
        return OpenLmisResponse.response("orderFillRate", this.lookupService.getOrderFillRate(geographicZoneId,periodId,facilityId,programId));
    }

    @RequestMapping(value = "/shipmentLeadTime", method = GET, headers = BaseController.ACCEPT_JSON)
    public ResponseEntity<OpenLmisResponse>  getShipmentLeadTime(@RequestParam("geographicZoneId") Long geographicZoneId,
                                                              @RequestParam("periodId") Long periodId,
                                                              @RequestParam("programId") Long programId){
        return OpenLmisResponse.response("leadTime", this.lookupService.getShipmentLeadTime(geographicZoneId,periodId,programId));
    }


    @RequestMapping(value = "/stockEfficiency", method = GET, headers = BaseController.ACCEPT_JSON)
    public ResponseEntity<OpenLmisResponse>  getStockEfficiencyData(@RequestParam("geographicZoneId") Long geographicZoneId,
                                                                    @RequestParam("periodId") Long periodId,
                                                                    @RequestParam("programId") Long programId,
                                                                    @RequestParam("productListId")List<Long> productListId){
        return OpenLmisResponse.response("stocking", this.lookupService.getStockEfficiencyData(geographicZoneId, periodId, programId, productListId));
    }
    @RequestMapping(value = "/stockEfficiencyDetail", method = GET, headers = BaseController.ACCEPT_JSON)
    public ResponseEntity<OpenLmisResponse>  getStockEfficiencyDetailData(@RequestParam("geographicZoneId") Long geographicZoneId,
                                                                    @RequestParam("periodId") Long periodId,
                                                                    @RequestParam("programId") Long programId,
                                                                    @RequestParam("productListId")List<Long> productListId){
        return OpenLmisResponse.response("stocking", this.lookupService.getStockEfficiencyDetailData(geographicZoneId, periodId, programId, productListId));
    }

}

@@ -850,16 +850,357 @@
 ller %7B%0A%0A
+    public static final String ITEM_FILL_RATE = %22itemFillRate%22;%0A    public static final String ORDER_FILL_RATE = %22orderFillRate%22;%0A    public static final String SHIPMENT_LEAD_TIME = %22leadTime%22;%0A    public static final String STOCKING_EFFICIENCY_STATICS = %22stocking%22;%0A    public static final String STOCKING_EFFICIENCY_DETAIL = %22stocking%22;%0A%0A%0A
     @Aut
@@ -1206,16 +1206,16 @@
 towired%0A
-
     Dash
@@ -1933,30 +1933,30 @@
 esponse(
-%22itemFillRate%22
+ITEM_FILL_RATE
 , this.l
@@ -2633,31 +2633,31 @@
 esponse(
-%22orderFillRate%22
+ORDER_FILL_RATE
 , this.l
@@ -3216,26 +3216,34 @@
 esponse(
-%22leadTime%22
+SHIPMENT_LEAD_TIME
 , this.l
@@ -3929,34 +3929,51 @@
 se.response(
-%22stocking%22
+STOCKING_EFFICIENCY_STATICS
 , this.looku
@@ -4689,26 +4689,42 @@
 esponse(
-%22stocking%22
+STOCKING_EFFICIENCY_DETAIL
 , this.l

set a public Key for returned data to access data from unit test