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.BbsFile;
import sgc.portal.com.com.persistence.ComYtaCalBbsFilePopMapper;
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;


/**
 *
 *
 * .
 *
 * @author KyungHee Jang(khjang@sgc.co.kr)
 * @version 1.0.0
 * @since  2020. 8. 2.
 */

@Transactional
@Service
public class ComYtaCalBbsFilePopService {

    @Autowired
    private ComYtaCalBbsFilePopMapper comYtaCalBbsFilePopMapper;

    /**
	 *
	 *
	 * @param
	 * @
	 *
	 */

    //조회
    public  List<EasyHashMap<String, Object>>  selectComYtaCalBbsFilePop(BbsFile bbsFile)
    {
	    return comYtaCalBbsFilePopMapper.selectComYtaCalBbsFilePop(bbsFile);
    }

	//등록, 수정, 삭제
    public void saveComYtaCalBbsFilePop(List<BbsFile> bbsFiles) {

	    if (CollectionUtils.isNotEmpty(bbsFiles)) {
	        for (BbsFile bbsFile : bbsFiles) {
	            switch (bbsFile.getRowStatus()) {
                case GridRowStatus.CREATED:
                    comYtaCalBbsFilePopMapper.insertComYtaCalBbsFilePop(bbsFile);
                    break;
                case GridRowStatus.UPDATED:
                    comYtaCalBbsFilePopMapper.updateComYtaCalBbsFilePop(bbsFile);
                    break;
                case GridRowStatus.DELETED:
                    comYtaCalBbsFilePopMapper.deleteComYtaCalBbsFilePop(bbsFile);
                    break;
                default:
                    throw new UnsupportedGirdStatusException();
	            }
            }
        }
    }
}
