package sgc.portal.cw.cw1505.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.cw1505.model.CW15050001U;
import sgc.portal.cw.cw1505.dto.CW15050001USearch;
import sgc.portal.cw.cw1505.persistence.CW15050001UMapper;

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

@Service
public class CW15050001UService {
    private final CW15050001UMapper mapper;

    public CW15050001UService(CW15050001UMapper mapper) {
        this.mapper = mapper;
    }

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

    @Transactional
    public Map<String, String> save(List<CW15050001U> CW15050001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CW15050001U cW15050001U : CW15050001U) {
            switch (cW15050001U.getRowStatus()) {
                case GridRowStatus.CREATED:
                    insert(cW15050001U);
                    break;
                case GridRowStatus.UPDATED:
                    update(cW15050001U);
                    break;
                case GridRowStatus.DELETED:
                    delete(cW15050001U);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }

    private void insert(CW15050001U cW15050001U) {
        mapper.insert(cW15050001U);
    }

    private void update(CW15050001U cW15050001U) {
        mapper.update(cW15050001U);
    }

    private void delete(CW15050001U cW15050001U) {
        mapper.delete(cW15050001U);
    }
}
