package sgc.portal.com.com.service;

import sgc.portal.base.exception.UnsupportedGirdStatusException;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.base.websquare.GridRowStatus;
import sgc.portal.com.com.model.Program;
import sgc.portal.com.com.persistence.ComPrgMapper;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**********************************************************
 * 시스템명  	: 시스템관리(COM)
 * 프로그램ID 	: ComPrgService
 * 프로그램명   	: 프로그램 관리 Service
 * @author	: SBK
 * @version	: 2023-07-25
 * @since JDK1.8
 * @see
 * 1. 최초 작성
**********************************************************/

@Transactional
@Service
public class ComPrgService
{

    @Autowired
    private ComPrgMapper comPrgMapper;

    public  List<EasyHashMap<String, Object>>  selectComPrgRegList(Program prg) {
        return comPrgMapper.selectComPrgRegList(prg);
    }

    public void saveComPrgRegInsert(List<Program> prgs) {

	    if (CollectionUtils.isNotEmpty(prgs)) {
            for(Program prg : prgs){
                switch (prg.getRowStatus()) {
                case GridRowStatus.CREATED:
                    comPrgMapper.saveComPrgRegInsert(prg);
                    break;
                case GridRowStatus.UPDATED:
                    comPrgMapper.saveComPrgRegUpdate(prg);
                    break;
                case GridRowStatus.DELETED:
                    comPrgMapper.saveComPrgRegDelete(prg);
                    break;
                default:
                    throw new UnsupportedGirdStatusException();
                }

            }
        }
    }

    public EasyHashMap<String, Object> selectPrgId(Program prg) {
        return comPrgMapper.selectPrgId(prg);
    }
}
