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.AuthGrp;
import sgc.portal.com.com.model.AuthUser;
import sgc.portal.com.com.persistence.ComAuthUserMngMapper;
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 mir(khjang@sgc.co.kr)
 * @version 1.0.0
 * @since  2020. 9. 5.
 */


@Service
public class ComAuthUserMngService
{

    @Autowired
    private ComAuthUserMngMapper comAuthUserMngMapper;

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

    public List<EasyHashMap<String, Object>> selectComAuthGrpMng(AuthGrp authgrps) {
	    return comAuthUserMngMapper.selectComAuthGrpMng(authgrps);
    }
    
    @Transactional
    public void saveComAuthGrpMng(List<AuthGrp> authgrps) {
	    if (CollectionUtils.isNotEmpty(authgrps)) {
            for (AuthGrp authgrp : authgrps) {
                switch (authgrp.getRowStatus()) {
                    case GridRowStatus.CREATED:
                        comAuthUserMngMapper.insertComAuthGrpMng(authgrp);
                        break;
                    case GridRowStatus.UPDATED:
                        comAuthUserMngMapper.updateComAuthGrpMng(authgrp);
                        break;
                    case GridRowStatus.DELETED:
                        comAuthUserMngMapper.deleteComAuthGrpMng(authgrp);
                        break;
                    default:
                        throw new UnsupportedGirdStatusException();
                }
            }
        }
    }

    public List<EasyHashMap<String, Object>> selectComAuthUserMng(AuthUser authusers) {
        return comAuthUserMngMapper.selectComAuthUserMng(authusers);
    }

    public List<EasyHashMap<String, Object>> selectComAuthUserNoMng(AuthUser authusers) {
        return comAuthUserMngMapper.selectComAuthUserNoMng(authusers);
    }
    
    @Transactional
    public void saveComAuthUserMng(List<AuthUser> authusers) {
        if (CollectionUtils.isNotEmpty(authusers)) {

            for (AuthUser authuser : authusers) {
                switch (authuser.getRowStatus()) {
                    case GridRowStatus.CREATED:
                        comAuthUserMngMapper.insertComAuthUserMng(authuser);
                        break;
                    case GridRowStatus.UPDATED:
                        comAuthUserMngMapper.updateComAuthUserMng(authuser);
                        break;
                    case GridRowStatus.DELETED:
                        comAuthUserMngMapper.deleteComAuthUserMng(authuser);
                        break;
                    default:
                        throw new UnsupportedGirdStatusException();
                }
            }
        }
    }
}
