package sgc.portal.cw.cw0601.service;

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.cw.cw0601.dto.CW06010001USearch;
import sgc.portal.cw.cw0601.model.CW06010001U;
import sgc.portal.cw.cw0601.persistence.CW06010001UMapper;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CW06010001UService {
    private final CW06010001UMapper mapper;

    public CW06010001UService(CW06010001UMapper mapper) {
        this.mapper = mapper;
    }

    public List<EasyHashMap<String, Object>> getList(CW06010001USearch search) {
        return mapper.getList(search);
    }
    
    @Transactional
    public Map<String, String> save(List<CW06010001U> CW06010001U) {
    	
    	Map<String,String> result = new HashMap<>();

        for (CW06010001U cW06010001U : CW06010001U) {

            switch (cW06010001U.getRowStatus()) {

            	case GridRowStatus.CREATED:
    				insert(cW06010001U);
    				
                default:
                    break;
            }
        }
        
        return result;
    }
    
    @Transactional
    public Map<String, String> updatePrev(List<CW06010001U> CW06010001U) {
    	
    	Map<String,String> result = new HashMap<>();

        for (CW06010001U cW06010001U : CW06010001U) {

            switch (cW06010001U.getRowStatus()) {

            	case GridRowStatus.UPDATED:
            		updatePrev(cW06010001U);
    				
                default:
                    break;
            }
        }
        
        return result;
    }
    
    @Transactional
    public Map<String, String> updateNext(List<CW06010001U> CW06010001U) {
    	
    	Map<String,String> result = new HashMap<>();

        for (CW06010001U cW06010001U : CW06010001U) {

            switch (cW06010001U.getRowStatus()) {

            	case GridRowStatus.UPDATED:
            		updateNext(cW06010001U);
    				
                default:
                    break;
            }
        }
        
        return result;
    }

    private void insert(CW06010001U cW06010001U) {
        mapper.insert(cW06010001U);
    }
    
    
    public void updatePrev(CW06010001U cW06010001U) {
    	
    	mapper.updatePrev(cW06010001U);
    }
    
    public void updateNext(CW06010001U cW06010001U) {
    	
    	mapper.updateNext(cW06010001U);
    }
}
