package sgc.portal.ei.ei0301.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import sgc.portal.base.util.EasyHashMap;
import sgc.portal.base.websquare.GridRowStatus;
import sgc.portal.ei.ei0101.model.EI01010001U;
import sgc.portal.ei.ei0301.dto.EI03010001USearch;
import sgc.portal.ei.ei0301.model.EI03010001U;

import sgc.portal.ei.ei0301.persistence.EI03010001UMapper;

import lombok.extern.slf4j.Slf4j;


@Slf4j
@Service
public class EI03010001UService {
    private final EI03010001UMapper mapper;

    public EI03010001UService(EI03010001UMapper mapper) {
        this.mapper = mapper;
    }
    
    /*
     * SEARCH LIST
     */
    public List<EasyHashMap<String, Object>> getList(EI03010001USearch search) {
        return mapper.getList(search);
    }
    
    public List<EasyHashMap<String, Object>> getList2(EI03010001USearch search) {
    	return mapper.getList2(search);
    }
    
    public List<EasyHashMap<String, Object>> getList3(EI03010001USearch search) {
        return mapper.getList3(search);
    }
    
    public List<EasyHashMap<String, Object>> getEqpDtlCd(EI03010001USearch search) {
        return mapper.getEqpDtlCd(search);
    }
    
    
    /*
     * SAVE LIST
     */
    @Transactional
    public Map<String, String> update1(List<EI03010001U> eI03010001U) {
    	Map<String,String> result = new HashMap<>();
    	for (EI03010001U vo : eI03010001U) {
    		update1(vo);
        }
    	
    	return result;
    }
    
    @Transactional
    public Map<String, String> update2(List<EI03010001U> eI03010001U) {
    	Map<String,String> result = new HashMap<>();
    	for (EI03010001U vo : eI03010001U) {
            update2(vo);
        }
    	
    	return result;
    }
    

    @Transactional
    public Map<String, String> save3(List<EI03010001U> eI03010001U) {
    	Map<String,String> result = new HashMap<>();
    	
    	for (EI03010001U vo : eI03010001U) {
            switch (vo.getRowStatus()) {
                case GridRowStatus.CREATED:
                	insert3(vo);
                    break;
                case GridRowStatus.UPDATED:
                    update3(vo);
                    break;
                case GridRowStatus.DELETED:
                	delete3(vo);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }
    
    
    /*
     * UPDATE
     */
    private void update1(EI03010001U eI03010001U) {
    	mapper.update1(eI03010001U);
    }
    
    private void update2(EI03010001U eI03010001U) {
    	mapper.update2(eI03010001U);
    }
    
    private void update3(EI03010001U eI03010001U) {
    	mapper.update3(eI03010001U);
    }
    
    
    /*
     * INSERT
     */
    private void insert3(EI03010001U eI03010001U) {
        mapper.insert3(eI03010001U);
    }
    
    
    /*
     * DELETE
     */
    private void delete3(EI03010001U eI03010001U) {
        mapper.delete3(eI03010001U);
    }
    
}
