package sgc.portal.cw.cw0630.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.cw0630.model.CW06300001U;
import sgc.portal.cw.cw0630.dto.CW06300001USearch;
import sgc.portal.cw.cw0630.persistence.CW06300001UMapper;

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

@Service
public class CW06300001UService {
    private final CW06300001UMapper mapper;

    public CW06300001UService(CW06300001UMapper mapper) {
        this.mapper = mapper;
    }

    public List<EasyHashMap<String, Object>> getList(CW06300001USearch search) {
        return mapper.getList(search);
    }

    public List<EasyHashMap<String, Object>> getListQA(CW06300001USearch search) {
        return mapper.getListQA(search);
    }
    
    @Transactional
    public Map<String, String> updateConf(List<CW06300001U> CW06300001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
        for (CW06300001U cW06300001U : CW06300001U) {
        	updateConf(cW06300001U);
        }
        return result;
    }
    
    private void updateConf(CW06300001U cW06300001U) {
        mapper.updateConf(cW06300001U);
    }
    
    @Transactional
    public Map<String, String> updateReturn(List<CW06300001U> CW06300001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
        for (CW06300001U cW06300001U : CW06300001U) {
        	updateReturn(cW06300001U);
        }
        return result;
    }
    
    private void updateReturn(CW06300001U cW06300001U) {
        mapper.updateReturn(cW06300001U);
    }

    @Transactional
    public Map<String, String> save(List<CW06300001U> CW06300001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CW06300001U cW06300001U : CW06300001U) {
            switch (cW06300001U.getRowStatus()) {
                case GridRowStatus.UPDATED:
                    update(cW06300001U);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }

    private void update(CW06300001U cW06300001U) {
        mapper.saveQA(cW06300001U);
    }
}
