package sgc.portal.cw.cw0625.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.cw0625.dto.CW06250001USearch;
import sgc.portal.cw.cw0625.model.CW06250001U;
import sgc.portal.cw.cw0625.persistence.CW06250001UMapper;

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

@Service
public class CW06250001UService {
    private final CW06250001UMapper mapper;

    public CW06250001UService(CW06250001UMapper mapper) {
        this.mapper = mapper;
    }

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

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

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