package sgc.portal.base.service;

//import kr.co.sgc.bo.hr.yta.calc.model.HrYtaMdcs;
import sgc.portal.base.exception.UnsupportedGirdStatusException;
import sgc.portal.base.model.ParticularsOfAccountPop;
import sgc.portal.base.persistence.ComParticularsOfAccountPopMapper;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.base.websquare.GridRowStatus;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 부서검색 서비스 구현.
 *
 * @author SDCIT
 * @version 1.0.0
 * @since 2020. 9. 22.
 */
@Service
public class ComParticularsOfAccountPopService {

    /** 매퍼 선언. */
    @Autowired
    private ComParticularsOfAccountPopMapper comParticularsOfAccountPopMapper;

    /**
     * Select particulars of account popup easy hash map.
     *
     * @param particularsOfAccountPop the particulars of account pop
     * @return the easy hash map
     */
    public EasyHashMap<String, Object> selectParticularsOfAccountPopup(ParticularsOfAccountPop particularsOfAccountPop) {
        return comParticularsOfAccountPopMapper.selectParticularsOfAccountPopup(particularsOfAccountPop);
    }

    /**
     * Select particulars of account popup list list.
     *
     * @param particularsOfAccountPop the particulars of account pop
     * @return the list
     */
    public List<EasyHashMap<String, Object>> selectParticularsOfAccountPopupList(@RequestBody ParticularsOfAccountPop particularsOfAccountPop) {
        return comParticularsOfAccountPopMapper.selectParticularsOfAccountPopupList(particularsOfAccountPop);
    }


    /**
     * Save particulars of account popup.
     *
     * @param particularsOfAccountPops the particulars of account pops
     */
    public void saveParticularsOfAccountPopup(List<ParticularsOfAccountPop> particularsOfAccountPops)
    {
        if (CollectionUtils.isNotEmpty(particularsOfAccountPops)) {
            for(ParticularsOfAccountPop particularsOfAccountPop : particularsOfAccountPops){
                switch (particularsOfAccountPop.getRowStatus()) {
                case GridRowStatus.CREATED:
                    particularsOfAccountPop.setNtsDatDivn("Z");
                    comParticularsOfAccountPopMapper.saveParticularsOfAccountPopupInsert(particularsOfAccountPop);
                    break;
                case GridRowStatus.UPDATED:
                    if("N".equals(particularsOfAccountPop.getPdfYn())){
                        if("1".equals(particularsOfAccountPop.getMdcsEvdcCd())){
                            particularsOfAccountPop.setNtsDatDivn("T");
                        }else{
                            particularsOfAccountPop.setNtsDatDivn("Z");
                        }
                    }
                    comParticularsOfAccountPopMapper.saveParticularsOfAccountPopupUpdate(particularsOfAccountPop);
                    break;
                case GridRowStatus.DELETED:
                    comParticularsOfAccountPopMapper.saveParticularsOfAccountPopupDelete(particularsOfAccountPop);
                    break;
                default:
                    throw new UnsupportedGirdStatusException();
                }
            }

//            HrYtaMdcs hrYtaMdcs = new HrYtaMdcs();
//            hrYtaMdcs.setCmpnCd(particularsOfAccountPops.get(0).getCmpnCd());   /* 회사 코드             */
//            hrYtaMdcs.setExcaYyd(particularsOfAccountPops.get(0).getExcaYyd()); /* 정산 연도             */
//            hrYtaMdcs.setEmpNo(particularsOfAccountPops.get(0).getEmpNo());     /* 사원 번호             */

//            comParticularsOfAccountPopMapper.saveHrYtaMdcsDelete(hrYtaMdcs);
//            comParticularsOfAccountPopMapper.saveHrYtaMdcsInsert(hrYtaMdcs);
        }
    }
}