package sgc.portal.base.web;

import sgc.portal.base.service.ComboSearchService;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.base.model.ComData;
import sgc.portal.com.com.model.CommDtl;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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


/**
 * 콤보 박스 컨트롤러.
 *
 * @author beomgeun.lee
* @version 1.0.0
 * @since 2020. 7. 5.
 */
@RestController
public class ComboSearchController {

    @Autowired
    private ComboSearchService comboSearchService;

    /**
     * Gets code list.
     *
     * @param param the param
     * @return the code list
     */
    //@PostMapping(value = "/getCodeList")
    //public JSONObject getCodeList(@RequestBody Map param) {
    //    return  comboSearchService.selectCodeList(param);
    //}

    /**
     * Gets code list.
     *
     * @param param the param
     * @return the code list
     */
    @GetMapping(value = "/getCodeList")
    public JSONObject getCodeList(@RequestParam(value="GRP_CD") String grpCd, @RequestParam(value="DATA_PREFIX") String dataPrefix) {
        Map param = new HashMap();
        Map dmaCommonCode = new HashMap();
        dmaCommonCode.put("GRP_CD", grpCd);
        dmaCommonCode.put("DATA_PREFIX", dataPrefix);
        param.put("dma_Common_Code", dmaCommonCode);
        return  comboSearchService.selectCodeList(param);
    }
    
    /**
     * Gets code list.
     *
     * @param param the param
     * @return the code list
     */
    @GetMapping(value = "/getCodeListEn")
    public JSONObject getCodeListEn(@RequestParam(value="GRP_CD") String grpCd, @RequestParam(value="DATA_PREFIX") String dataPrefix) {
        Map param = new HashMap();
        Map dmaCommonCode = new HashMap();
        dmaCommonCode.put("GRP_CD", grpCd);
        dmaCommonCode.put("DATA_PREFIX", dataPrefix);
        param.put("dma_Common_Code", dmaCommonCode);
        return  comboSearchService.selectCodeListEn(param);
    }
    
    /**
     * Gets code list.
     *
     * @param param the param
     * @return the code list
     */
    @GetMapping(value = "/getCodeCmpnList")
    public JSONObject getCodeCmpnList(@RequestParam(value="CMPN") String cmpn, @RequestParam(value="GRP_CD") String grpCd, @RequestParam(value="DATA_PREFIX") String dataPrefix) {
        Map param = new HashMap();
        Map dmaCommonCode = new HashMap();
        dmaCommonCode.put("CMPN", cmpn);
        dmaCommonCode.put("GRP_CD", grpCd);
        dmaCommonCode.put("DATA_PREFIX", dataPrefix);
        param.put("dma_Common_Code", dmaCommonCode);
        return  comboSearchService.selectCodeCmpnList(param);
    }

    /**
     * 설정코드에 따른 콤보 리스트 조회
     *
     * @param param the param
     * @return list
     */
    @PostMapping(value = "/selectCommCodeList")
    public List<EasyHashMap<String, Object>> selectCommCodeList(@RequestBody CommDtl param) {
        return  comboSearchService.selectCommCodeList(param);
    }
}