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.Cmpn;
import sgc.portal.com.com.persistence.ComCmpnMngMapper;
import sgc.portal.com.com.persistence.ComCovendMngMapper;
import sgc.portal.security.annotation.Secured;
import sgc.portal.security.annotation.SecurityPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * The type Com cmpn mng service.
 *
 * @author KyungHee Jang(khjang@sgc.co.kr)
 * @version 1.0.0
 * @since 2020. 8. 2.
 */
@Transactional
@Service
public class ComCmpnMngService
{

    @Autowired
    private ComCmpnMngMapper comCmpnMngMapper;

    @Autowired
    private ComCovendMngMapper comCovendMngMapper;
    
    public List<EasyHashMap<String, Object>> getAll() {
        return comCmpnMngMapper.getAll();
    }
    
    public List<EasyHashMap<String, Object>> getAsAll() {
        return comCovendMngMapper.getAll();
    }
    
    
    public List<EasyHashMap<String, Object>> getCmpn(Cmpn cmpns) {
        return comCmpnMngMapper.getCmpn(cmpns);
    }

    /**
     * Select com cmpn mng list.
     *
     * @param cmpns the cmpns
     * @return the list
     */
    public  List<EasyHashMap<String, Object>>  selectComCmpnMng(Cmpn cmpns)
    {
	    return comCmpnMngMapper.selectComCmpnMng(cmpns);
    }

    /**
     * Save com cmpn mng.
     *
     * @param cmpns the cmpns
     */
//등록, 수정, 삭제
	@Secured(policy = SecurityPolicy.NONE)
    public void saveComCmpnMng(List<Cmpn> cmpns)
    {
        for(Cmpn cmpn : cmpns){
            switch (cmpn.getRowStatus()) {
            case GridRowStatus.CREATED:
                comCmpnMngMapper.insertComCmpnMng(cmpn);
                break;
            case GridRowStatus.UPDATED:
                comCmpnMngMapper.updateComCmpnMng(cmpn);
                break;
            case GridRowStatus.DELETED:
                comCmpnMngMapper.deleteComCmpnMng(cmpn);
                break;
            default:
                throw new UnsupportedGirdStatusException();
            }
        }
    }
}
