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.GrpPrg;
import sgc.portal.com.com.model.Menu;
import sgc.portal.com.com.model.Program;
import sgc.portal.com.com.persistence.ComAuthPrgMngMapper;
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. 8. 2.
 */
@Transactional
@Service
public class ComAuthPrgMngService {

    @Autowired
    private ComAuthPrgMngMapper comAuthPrgMngMapper;

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

    public List<EasyHashMap<String, Object>> selectComAuthPrgGrpMng(AuthGrp authgrps) {
        return comAuthPrgMngMapper.selectComAuthPrgGrpMng(authgrps);
    }

    public void saveComAuthPrgMenuMng(List<Menu> menus) {
        if (CollectionUtils.isNotEmpty(menus)) {
            for (Menu menu : menus) {
                comAuthPrgMngMapper.insertComAuthPrgMenuMng(menu);
            }
        }
    }

    public void saveComAuthPrgMng(List<GrpPrg> grpprgs) {

        if (CollectionUtils.isNotEmpty(grpprgs)) {
            for (GrpPrg grpprg : grpprgs) {
                switch (grpprg.getRowStatus()) {
                    case GridRowStatus.CREATED:
                        comAuthPrgMngMapper.insertComAuthPrgMng(grpprg);
                        break;
                    case GridRowStatus.UPDATED:
                        comAuthPrgMngMapper.updateComAuthPrgMng(grpprg);
                        break;
                    case GridRowStatus.DELETED:
                        comAuthPrgMngMapper.deleteComAuthPrgMng(grpprg);
                        break;
                    default:
                        throw new UnsupportedGirdStatusException();
                }
            }

        }
    }

    public void deleteComAuthPrgMenuMng(List<GrpPrg> grpprgs) {
        if (CollectionUtils.isNotEmpty(grpprgs)) {
            for (GrpPrg grpprg : grpprgs) {
                if (GridRowStatus.DELETED.equals(grpprg.getRowStatus())) {
                    comAuthPrgMngMapper.deleteComAuthPrgMenuMng(grpprg);
                }
            }
        }
    }
  
  public List<EasyHashMap<String, Object>> selectComAuthPrgMng(GrpPrg grpprgs) {
        return comAuthPrgMngMapper.selectComAuthPrgMng(grpprgs);
   }

  
  public List<EasyHashMap<String, Object>> selectComAuthPrgMenuMng(Menu menus) {
        return comAuthPrgMngMapper.selectComAuthPrgMenuMng(menus);
  }

  
  public List<EasyHashMap<String, Object>> selectComAuthPrgPrgMng(Program prgs) {
        return comAuthPrgMngMapper.selectComAuthPrgPrgMng(prgs);
  }

}
