package sgc.portal.cw.cw0606.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.cw0606.dto.CW06060001USearch;
import sgc.portal.cw.cw0606.model.CW06060001U;
import sgc.portal.cw.cw0606.persistence.CW06060001UMapper;

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

@Service
public class CW06060001UService {
    private final CW06060001UMapper mapper;

    public CW06060001UService(CW06060001UMapper mapper) {
        this.mapper = mapper;
    }

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

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

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

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

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

    private void update(CW06060001U cW06060001U) {
        mapper.update(cW06060001U);
    }
    
    @Transactional
    public Map<String, String> approve(List<CW06060001U> CW06060001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
        for (CW06060001U cW06060001U : CW06060001U) {
        	approve(cW06060001U);
        }
        return result;
    }
    
    private void approve(CW06060001U cW06060001U) {
        mapper.approve(cW06060001U);
    }
    
    @Transactional
    public Map<String, String> cancel(List<CW06060001U> CW06060001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
        for (CW06060001U cW06060001U : CW06060001U) {
        	cancel(cW06060001U);
        }
        return result;
    }
    
    private void cancel(CW06060001U cW06060001U) {
        mapper.cancel(cW06060001U);
    }
    
    @Transactional
    public void saveAnswer(CW06060001U cW06060001U) {
    	mapper.saveAnswer(cW06060001U);	
    }
    
    @Transactional
    public void saveSafeAnswer(CW06060001U cW06060001U) {
    	mapper.saveSafeAnswer(cW06060001U);	
    }
}
