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.Comm;
import sgc.portal.com.com.model.CommDtl;
import sgc.portal.com.com.persistence.ComCommMngMapper;
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 ComCommMngService
{

    @Autowired
    private ComCommMngMapper comCommMngMapper;

    public  List<EasyHashMap<String, Object>>  selectComCommMng(Comm comms)
    {
	    return comCommMngMapper.selectComCommMng(comms);

    }

	//등록, 수정, 삭제
    public  void  saveComCommMng(List<Comm> comms)
    {
	    if (CollectionUtils.isNotEmpty(comms)) {
            for (Comm comm : comms) {
                switch (comm.getRowStatus()) {
                case GridRowStatus.CREATED:
                    comCommMngMapper.insertComCommMng(comm);
                    break;
                case GridRowStatus.UPDATED:
                    comCommMngMapper.updateComCommMng(comm);
                    break;
                case GridRowStatus.DELETED:
                    comCommMngMapper.deleteComCommMng(comm);
                    break;
                default:
                    throw new UnsupportedGirdStatusException();
                }
            }
        }
    }

    public  List<EasyHashMap<String, Object>>  selectComCommDtlMng(CommDtl commdtls)
    {
        return comCommMngMapper.selectComCommDtlMng(commdtls);
    }

	//등록, 수정, 삭제
    public  void  saveComCommDtlMng(List<CommDtl> commdtls)
    {
        if (CollectionUtils.isNotEmpty(commdtls)) {
            for (CommDtl commdtl : commdtls) {
                switch (commdtl.getRowStatus()) {
                case GridRowStatus.CREATED:
                    comCommMngMapper.insertComCommDtlMng(commdtl);
                    break;
                case GridRowStatus.UPDATED:
                    comCommMngMapper.updateComCommDtlMng(commdtl);
                    break;
                case GridRowStatus.DELETED:
                    comCommMngMapper.deleteComCommDtlMng(commdtl);
                    break;
                default:
                    throw new UnsupportedGirdStatusException();
                }
            }
        }
    }
}
