package sgc.portal.cs.cs0201.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.com.auth.model.PrvtinfoFindHist;
import sgc.portal.com.auth.model.SmComHdlgAuth;
import sgc.portal.com.auth.service.MaskingDesabledService;
import sgc.portal.com.com.service.ComAuthUserMngService;
import sgc.portal.cs.cs0201.service.CS02010001UService;
import sgc.portal.cs.cs0402.dto.CS04020001USearch;
import sgc.portal.cs.cs0201.dto.CS02010001USearch;
import sgc.portal.cs.cs0201.model.CS02010001U;
import sgc.portal.cs.cs0201.model.CS02010004U;
import sgc.portal.cs.cs0201.model.CS02010006U;
import sgc.portal.cs.cs0201.model.CS02010007U;

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

@RestController
@RequestMapping("/cs/cs0201")
public class CS02010001UController {
	
	private final CS02010001UService service;

    public CS02010001UController(CS02010001UService service) {
        this.service = service;
    }

    //현장협력업체정보 팝업 조회
    @PostMapping("/CS02010001U/selectTcsSitePopList")
    public List<EasyHashMap<String, Object>> selectTcsSitePopList(@RequestBody CS02010001USearch search) {
        return service.selectTcsSitePopList(search);
    }
    
    //현장협력업체정보  조회
    @PostMapping("/CS02010001U/selectSmComCovendSiteTradeList")
    public List<EasyHashMap<String, Object>> selectSmComCovendSiteTradeList(@RequestBody CS02010001USearch search) {
        return service.selectSmComCovendSiteTradeList(search);
    }
    
    //협력 업체 담당자  조회
    @PostMapping("/CS02010001U/selectSmComCovendMapList")
    public EasyHashMap<String, Object> selectSmComCovendMapList(@RequestBody CS02010001USearch search) {
        return service.selectSmComCovendMapList(search);
    }
    
    @PostMapping("/CS02010001U/selectTcsSiteTradeChrgrList")
    public List<EasyHashMap<String, Object>> selectTcsSiteTradeChrgrList(@RequestBody CS02010001USearch search) {
        return service.selectTcsSiteTradeChrgrList(search);
    }
    
    @PostMapping("/CS02010001U/selectConvendTcsSiteTradeList")
    public List<EasyHashMap<String, Object>> selectConvendTcsSiteTradeList(@RequestBody CS02010001USearch search) {
        return service.selectConvendTcsSiteTradeList(search);
    }
    
    @PostMapping("/CS02010001U/selectConvendTcsSiteTradeItemList")
    public List<EasyHashMap<String, Object>> selectConvendTcsSiteTradeItemList(@RequestBody CS02010001USearch search) {
        return service.selectConvendTcsSiteTradeItemList(search);
    }
    
    @PostMapping("/CS02010001U/selectConvendTcsSiteTradeGuarList")
    public List<EasyHashMap<String, Object>> selectConvendTcsSiteTradeGuarList(@RequestBody CS02010001USearch search) {
        return service.selectConvendTcsSiteTradeGuarList(search);
    }
    
    @PostMapping("/CS02010001U/saveTcsSiteTrade")
    public Map<String, String> saveTcsSiteTrade(@RequestBody CS02010004U cS02010004U) {
    	return service.saveTcsSiteTrade(cS02010004U);
    }
    
    @PostMapping("/CS02010001U/deleteTcsSiteTrade")
    public Map<String, String> deleteTcsSiteTrade(@RequestBody CS02010004U cS02010004U) {
    	return service.deleteTcsSiteTrade(cS02010004U);
    }
    
    @PostMapping("/CS02010001U/updateIfTcsSiteTrade")
    public Map<String, String> updateIfTcsSiteTrade(@RequestBody CS02010004U cS02010004U) {
    	return service.updateIfTcsSiteTrade(cS02010004U);
    }
    
    @PostMapping("/CS02010001U/selectSmComCovendPopList")
    public List<EasyHashMap<String, Object>> selectSmComCovendPopList(@RequestBody CS02010001USearch search) {
        return service.selectSmComCovendPopList(search);
    }
    
    //동적조회 
    @PostMapping("/CS02010001U/saveSmComCovendNew")
    public Map<String, Object> saveSmComCovendNew(@RequestBody CS02010001USearch search) {
    	
    	Map<String, Object> resultMap = new HashMap<String, Object>();
    	
    	int count1 = service.selectTcsSiteTradeNewCheckCount(search);
    	
    	EasyHashMap<String, Object>  Map1 = service.selectSmComCovendMapNewList(search);
    	List<EasyHashMap<String, Object>>  list1 = service.selectSmComCovendChrgrNewList(search);
    	int count21 = service.selectSmComCovendAS1(search);
    	int count22 = service.selectSmComCovendAS2(search);
    	int count23 = service.selectSmComCovendAS3(search);
    	
    	if(count1 > 0) {
    		resultMap.put("count", "0");
    		resultMap.put("message", "등록이 불가능합니다.");
    	}else if(count1 == 0) {
    		resultMap.put("count", "1");	
    		resultMap.put("dcsearchMapSmComCovend"		, Map1);
        	resultMap.put("dcdataList2"					, list1);
        	resultMap.put("dcdataList2Count1"			, count21);
        	resultMap.put("dcdataList2Count2"			, count22);
        	resultMap.put("dcdataList2Count3"			, count23);
    	}     
        return resultMap;
    }
    
    @PostMapping("/CS02010001U/convendTcsSiteTradefileCheck")
    public  Map<String, String> convendTcsSiteTradefileCheck(@RequestBody CS02010006U cS02010006U) {
        return service.convendTcsSiteTradefileCheck(cS02010006U);
    }
    
    @PostMapping("/CS02010001U/selectSmComCovendAS")
    public Map<String, Object> selectSmComCovendAS1(@RequestBody CS02010001USearch search) {
    	Map<String, Object> resultMap = new HashMap<String, Object>();
    	
    	int count21 = service.selectSmComCovendAS1(search);
    	int count22 = service.selectSmComCovendAS2(search);
    	int count23 = service.selectSmComCovendAS3(search);
    	
    	resultMap.put("dcdataList2Count1"			, count21);
    	resultMap.put("dcdataList2Count2"			, count22);
    	resultMap.put("dcdataList2Count3"			, count23);

    	return resultMap;
    }
}
