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.AuthUserPrg;
import sgc.portal.com.com.persistence.ComAuthUserPrgMngMapper;
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.
 */

@Transactional
@Service
public class ComAuthUserPrgMngService
{

    @Autowired
    private ComAuthUserPrgMngMapper comAuthUserPrgMngMapper;

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

    public List<EasyHashMap<String, Object>> selectComAuthPrgMngGrp(AuthUserPrg authUserPrg) {
	    return comAuthUserPrgMngMapper.selectComAuthPrgMngGrp(authUserPrg);
    }

    public List<EasyHashMap<String, Object>> selectComAuthPrgMngMenu(AuthGrp authGrp) {
        return comAuthUserPrgMngMapper.selectComAuthPrgMngMenu(authGrp);
    }

    public List<EasyHashMap<String, Object>> selectComAuthPrgMngUser(AuthUserPrg authUserPrg) {
        return comAuthUserPrgMngMapper.selectComAuthPrgMngUser(authUserPrg);
    }

    public List<EasyHashMap<String, Object>> selectComAuthPrgMngUserDtl(AuthUserPrg authUserPrg) {
        return comAuthUserPrgMngMapper.selectComAuthPrgMngUserDtl(authUserPrg);
    }

    /*

    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);
    }
*/
    public void saveComAuthPrgMngUser(List<AuthUserPrg> authUserPrgs) {
        if (CollectionUtils.isNotEmpty(authUserPrgs)) {

            for(AuthUserPrg authUserPrg : authUserPrgs) {
                switch (authUserPrg.getRowStatus()) {
                    case GridRowStatus.CREATED:
                        comAuthUserPrgMngMapper.insertComAuthPrgMngUser(authUserPrg);
                        break;
                    case GridRowStatus.UPDATED:
                        comAuthUserPrgMngMapper.updateComAuthPrgMngUser(authUserPrg);
                        break;
                    case GridRowStatus.DELETED:
                        comAuthUserPrgMngMapper.deleteComAuthPrgMngUser(authUserPrg);
                        break;
                    default:
                        throw new UnsupportedGirdStatusException();
                }
            }
        }
    }


    public void saveComAuthPrgMngUserDtl(List<AuthUserPrg> authUserPrgs) {
        if (CollectionUtils.isNotEmpty(authUserPrgs)) {

            for(AuthUserPrg authUserPrg : authUserPrgs) {
                switch (authUserPrg.getRowStatus()) {
                    case GridRowStatus.CREATED:
                        comAuthUserPrgMngMapper.insertComAuthPrgMngUserDtl(authUserPrg);
                        break;
                    case GridRowStatus.UPDATED:
                        comAuthUserPrgMngMapper.updateComAuthPrgMngUserDtl(authUserPrg);
                        break;
                    case GridRowStatus.DELETED:
                        comAuthUserPrgMngMapper.deleteComAuthPrgMngUserDtl(authUserPrg);
                        break;
                    default:
                        throw new UnsupportedGirdStatusException();
                }
            }
        }
    }

}
