package sgc.portal.cw.cw0608.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.cw0608.model.CW06080001U;
import sgc.portal.cw.cw0608.dto.CW06080001USearch;
import sgc.portal.cw.cw0608.persistence.CW06080001UMapper;

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

@Service
public class CW06080001UService {
    private final CW06080001UMapper mapper;

    public CW06080001UService(CW06080001UMapper mapper) {
        this.mapper = mapper;
    }

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

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

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

    private void update(CW06080001U cW06080001U) {
        mapper.saveQA(cW06080001U);
    }
}
