package sgc.portal.as.as0102.web;

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

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import sgc.portal.as.as0102.dto.AS01020001USearch;
import sgc.portal.as.as0102.model.AS01020001U;
import sgc.portal.as.as0102.model.AS01020002U;
import sgc.portal.as.as0102.service.AS01020001UService;
import sgc.portal.base.exception.BusinessException;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.com.sym.user.model.UserDetails;

@RestController
@RequestMapping("/as/as0102")
public class AS01020001UController {
	
	/**
	 * 
	 */
	private final AS01020001UService service;

    /**
     * @param service
     */
    public AS01020001UController(AS01020001UService service) {
        this.service = service;
    }

    /**
     * @param userDetails
     * @param search
     */
    private void setFillSearch(UserDetails userDetails, AS01020001USearch search) {
    	search.setCmpnCd(userDetails.getCmpnCd());
    	search.setCovendId(userDetails.getCovendId());
    	String covendId = userDetails.getCovendId();
    	
    	if (covendId == null || "".equals(covendId)) {
    		throw new BusinessException("협력업체만 접근 가능합니다.");
    	}
    }
    
	/**
	 * @param userDetails
	 * @param search
	 * @return
	 */
	@PostMapping("/AS01020001U/selectSmComCovendList")
    public List<EasyHashMap<String, Object>> selectSmComCovendList(UserDetails userDetails, @RequestBody AS01020001USearch search) {
    	setFillSearch(userDetails, search);
        return service.selectSmComCovendList(search);
    }
    
    /**
     * @param userDetails
     * @param search
     * @return
     */
    @PostMapping("/AS01020001U/selectSmComCovendPopList")
    public EasyHashMap<String, Object> selectSmComCovendPopList(UserDetails userDetails, @RequestBody AS01020001USearch search) {
    	setFillSearch(userDetails, search);
        return service.selectSmComCovendPopList(search);
    }
    
    /**
     * @param userDetails
     * @param search
     * @return
     */
    @PostMapping("/AS01020001U/selectSmComCovendTypePopList")
    public List<EasyHashMap<String, Object>> selectSmComCovendTypePopList(UserDetails userDetails, @RequestBody AS01020001USearch search) {
    	setFillSearch(userDetails, search);
        return service.selectSmComCovendTypePopList(search);
    }
    
    //협력업체 담당자정보 조회
    /**
     * @param userDetails
     * @param search
     * @return
     */
    @PostMapping("/AS01020001U/selectSmComCovendChrgrPopList")
    public List<EasyHashMap<String, Object>> selectSmComCovendChrgrPopList(UserDetails userDetails, @RequestBody AS01020001USearch search) {
    	setFillSearch(userDetails, search);
        return service.selectSmComCovendChrgrPopList(search);
    }
    
    /**
     * 자사 담당자 정보 가져오기
     * 
     * @param userDetails
     * @param search
     * @return
     */
    @PostMapping("/AS01020001U/selectSmComCovendChrgrUserIdList")
    public List<EasyHashMap<String, Object>> selectSmComCovendChrgrUserIdList(UserDetails userDetails, @RequestBody AS01020001USearch search) {
    	setFillSearch(userDetails, search);
        return service.selectSmComCovendChrgrUserIdList(search);
    }
    
    /**
     * 자사 정보 수정
     * 
     * @param userDetails
     * @param cS00010001U
     * @return
     */
    @PostMapping("/AS01020001U/saveSmComCovend")
    public Map<String, String> saveSmComCovend(UserDetails userDetails, @RequestBody AS01020001U cS00010001U) {
    	return service.saveSmComCovend(cS00010001U);
    }
    
    //협력업체 담당자정보팝업  등록
    /**
     * @param userDetails
     * @param AS01020002U
     * @return
     */
    @PostMapping("/AS01020001U/saveSmComCovendChrgr")
    public Map<String, String> saveSmComCovendChrgr(UserDetails userDetails, @RequestBody List<AS01020002U> AS01020002U) {
    	return service.saveSmComCovendChrgr(AS01020002U);
    }
    
    //협력업체  첨부파일
    @PostMapping("/AS01020001U/updateSmComCovendAflId")
    public Map<String, String> updateSmComCovendAflId(UserDetails userDetails, @RequestBody AS01020001U cS00010001U) {
    	return service.updateSmComCovendAflId(cS00010001U);
    }
}
