package sgc.portal.cd.cd0201.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import sgc.portal.base.util.EasyHashMap;
import sgc.portal.base.websquare.GridRowStatus;
import sgc.portal.cd.cd0201.dto.CD02010001USearch;
import sgc.portal.cd.cd0201.persistence.CD02010001UMapper;
import sgc.portal.cd.cd0201.model.CD02010001U;
import sgc.portal.cd.cd0201.model.ConDayWrk;
import sgc.portal.cd.cd0201.model.ConDayWrkCn;

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

@Service
public class CD02010001UService {
    private final CD02010001UMapper mapper;

    public CD02010001UService(CD02010001UMapper mapper) {
        this.mapper = mapper;
    }
    
    //CON_DAY_WRK 현장일보
    public List<EasyHashMap<String, Object>> getListConDayWrkCalKo(CD02010001USearch search) {
        return mapper.getListConDayWrkCalKo(search);
    }
    
    public List<EasyHashMap<String, Object>> getListConDayWrkCalEn(CD02010001USearch search) {
        return mapper.getListConDayWrkCalEn(search);
    }
    
    //CON_DAY_WRK 업무
    public EasyHashMap<String, Object> getListConDayWrk(CD02010001USearch search) {
        return mapper.getListConDayWrk(search);
    }
    
    @Transactional
    public Map<String, String> saveConDayWrk(CD02010001U cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	ConDayWrk conDayWrk = cD02010001U.getDcConDayWrk();
		List<ConDayWrkCn> conDayWrkCn = cD02010001U.getDcConDayWrkCn();
		
		switch (conDayWrk.getRowStatus()) {
	        case GridRowStatus.CREATED:
	        	mapper.insertConDayWrk(conDayWrk);
	            break;
	        case GridRowStatus.UPDATED:
	        	mapper.updateConDayWrk(conDayWrk);
	            break;
	        case GridRowStatus.DELETED:
	        	mapper.deleteConDayWrk(conDayWrk);
	            break;
	        default:
	            break;
	    }
    	
    	for (ConDayWrkCn vo : conDayWrkCn) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                	mapper.insertConDayWrkCn(vo);
                    break;
                case GridRowStatus.UPDATED:
                	mapper.updateConDayWrkCn(vo);
                    break;
                case GridRowStatus.DELETED:
                	mapper.deleteConDayWrkCn(vo);
                    break;
                default:
                    break;
            }
        }
    	
    	return result;
    }
    
    @Transactional
    public Map<String, String> saveConDayWrkAll(CD02010001U cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	ConDayWrk conDayWrk = cD02010001U.getDcConDayWrk();
		List<ConDayWrkCn> conDayWrkCn = cD02010001U.getDcConDayWrkCn();
		
		switch (conDayWrk.getRowStatus()) {
	        case GridRowStatus.CREATED:
	            break;
	        case GridRowStatus.UPDATED:
	            break;
	        case GridRowStatus.DELETED:
	        	mapper.deleteConDayWrk(conDayWrk);
	            break;
	        default:
	            break;
	    }
    	
    	for (ConDayWrkCn vo : conDayWrkCn) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                    break;
                case GridRowStatus.UPDATED:
                    break;
                case GridRowStatus.DELETED:
                	mapper.deleteConDayWrkCn(vo);
                	mapper.deleteConDayWrkManAll(vo);
                	mapper.deleteConDayWrkEqAll(vo);
                	mapper.deleteConDayWrkEqprtAll(vo);
                	mapper.deleteConDayWrkBdAll(vo);
                	mapper.deleteConDayWrkBdprtAll(vo);
                	mapper.deleteConDayWrkPrAll(vo);
                	mapper.deleteConDayWrkPtAll(vo);
                    break;
                default:
                    break;
            }
        }
    	
    	return result;
    }
    
    //draft
    @Transactional
    public Map<String, String> draft(CD02010001U cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	mapper.updateDraft(cD02010001U);
    	
    	return result;
    }
    
    //CON_DAY_WRK_CN 업무
    public List<EasyHashMap<String, Object>> getListConDayWrkCn(CD02010001USearch search) {
        return mapper.getListConDayWrkCn(search);
    }
    
    //CON_DAY_WRK_MANPWR 출역인원
    public List<EasyHashMap<String, Object>> getListConDayWrkMan(CD02010001USearch search) {
        return mapper.getListConDayWrkMan(search);
    }
    
    @Transactional
    public Map<String, String> saveConDayWrkMan(List<CD02010001U> cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CD02010001U vo : cD02010001U) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                	mapper.insertConDayWrkMan(vo);
                    break;
                case GridRowStatus.UPDATED:
                	mapper.updateConDayWrkMan(vo);
                    break;
                case GridRowStatus.DELETED:
                	mapper.deleteConDayWrkMan(vo);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }
    
    //CON_DAY_WRK_EQPM 주요장비
    public List<EasyHashMap<String, Object>> getListConDayWrkEq(CD02010001USearch search) {
        return mapper.getListConDayWrkEq(search);
    }
    
    @Transactional
    public Map<String, String> saveConDayWrkEq(List<CD02010001U> cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CD02010001U vo : cD02010001U) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                	mapper.insertConDayWrkEq(vo);
                	mapper.insertConDayWrkEqprt(vo);
                    break;
                case GridRowStatus.UPDATED:
                	mapper.updateConDayWrkEq(vo);
                	mapper.insertConDayWrkEqprt(vo);
                    break;
                case GridRowStatus.DELETED:
                	mapper.deleteConDayWrkEq(vo);
                	mapper.insertConDayWrkEqprt(vo);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }
    
    //CON_DAY_WRK_EQPMPRT 주요장비출력
    public List<EasyHashMap<String, Object>> getListConDayWrkEqprt(CD02010001USearch search) {
        return mapper.getListConDayWrkEqprt(search);
    }
    
    @Transactional
    public Map<String, String> saveConDayWrkEqprt(List<CD02010001U> cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CD02010001U vo : cD02010001U) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                	mapper.insertConDayWrkEqprt(vo);
                    break;
                case GridRowStatus.UPDATED:
                	mapper.updateConDayWrkEqprt(vo);
                    break;
                case GridRowStatus.DELETED:
                	mapper.deleteConDayWrkEqprt(vo);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }
    
    //CON_DAY_WRK_BDMT 주요자재
    public List<EasyHashMap<String, Object>> getListConDayWrkBd(CD02010001USearch search) {
        return mapper.getListConDayWrkBd(search);
    }
    
    @Transactional
    public Map<String, String> saveConDayWrkBd(List<CD02010001U> cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CD02010001U vo : cD02010001U) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                	mapper.insertConDayWrkBd(vo);
                	mapper.insertConDayWrkBdprt(vo);
                    break;
                case GridRowStatus.UPDATED:
                	mapper.updateConDayWrkBd(vo);
                	mapper.insertConDayWrkBdprt(vo);
                    break;
                case GridRowStatus.DELETED:
                	mapper.deleteConDayWrkBd(vo);
                	mapper.insertConDayWrkBdprt(vo);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }
    
    //CON_DAY_WRK_BDMTPRT 주요자재출력
    public List<EasyHashMap<String, Object>> getListConDayWrkBdprt(CD02010001USearch search) {
        return mapper.getListConDayWrkBdprt(search);
    }
    
    @Transactional
    public Map<String, String> saveConDayWrkBdprt(List<CD02010001U> cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CD02010001U vo : cD02010001U) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                	mapper.insertConDayWrkBdprt(vo);
                    break;
                case GridRowStatus.UPDATED:
                	mapper.updateConDayWrkBdprt(vo);
                    break;
                case GridRowStatus.DELETED:
                	mapper.deleteConDayWrkBdprt(vo);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }
    
    //CON_DAY_WRK_PROG Progress
    public List<EasyHashMap<String, Object>> getListConDayWrkPr(CD02010001USearch search) {
        return mapper.getListConDayWrkPr(search);
    }
    
    @Transactional
    public Map<String, String> saveConDayWrkPr(List<CD02010001U> cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CD02010001U vo : cD02010001U) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                	mapper.insertConDayWrkPr(vo);
                    break;
                case GridRowStatus.UPDATED:
                	mapper.updateConDayWrkPr(vo);
                    break;
                case GridRowStatus.DELETED:
                	mapper.deleteConDayWrkPr(vo);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }
    
    //CON_DAY_WRK_PHOTO 공정사진
    public List<EasyHashMap<String, Object>> getListConDayWrkPt(CD02010001USearch search) {
        return mapper.getListConDayWrkPt(search);
    }
    
    @Transactional
    public Map<String, String> saveConDayWrkPt(List<CD02010001U> cD02010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CD02010001U vo : cD02010001U) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                	mapper.insertConDayWrkPt(vo);
                    break;
                case GridRowStatus.UPDATED:
                	mapper.updateConDayWrkPt(vo);
                    break;
                case GridRowStatus.DELETED:
                	mapper.deleteConDayWrkPt(vo);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }
    
    //CON_DAY_MST_JOBTYP 공종마스터
    public List<EasyHashMap<String, Object>> getListConDayMstJobtypKo(CD02010001USearch search) {
        return mapper.getListConDayMstJobtypKo(search);
    }
    
    public List<EasyHashMap<String, Object>> getListConDayMstJobtypEn(CD02010001USearch search) {
        return mapper.getListConDayMstJobtypEn(search);
    }
    
    //CON_DAY_MST_EQPM 장비마스터
    public List<EasyHashMap<String, Object>> getListConDayMstEqpmKo(CD02010001USearch search) {
        return mapper.getListConDayMstEqpmKo(search);
    }
    
    public List<EasyHashMap<String, Object>> getListConDayMstEqpmEn(CD02010001USearch search) {
        return mapper.getListConDayMstEqpmEn(search);
    }
    
    //CON_DAY_MST_BDMT 자재마스터
    public List<EasyHashMap<String, Object>> getListConDayMstBdmtKo(CD02010001USearch search) {
        return mapper.getListConDayMstBdmtKo(search);
    }
    
    public List<EasyHashMap<String, Object>> getListConDayMstBdmtEn(CD02010001USearch search) {
        return mapper.getListConDayMstBdmtEn(search);
    }
    
    //CON_DAY_SITE_COVEND 공사일보)협력업체
    public List<EasyHashMap<String, Object>> getListConDaySiteCovend(CD02010001USearch search) {
        return mapper.getListConDaySiteCovend(search);
    }
}
