package sgc.portal.cw.cw0104.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.cw0104.dto.CW01040001USearch;
import sgc.portal.cw.cw0104.model.CW01040001U;
import sgc.portal.cw.cw0104.persistence.CW01040001UMapper;

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

@Service
public class CW01040001UService {
    private final CW01040001UMapper mapper;

    public CW01040001UService(CW01040001UMapper mapper) {
        this.mapper = mapper;
    }

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

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

    private void insert(CW01040001U cW01040001U) {
        mapper.insert(cW01040001U);
    }

    private void update(CW01040001U cW01040001U) {
        mapper.update(cW01040001U);
    }

    private void delete(CW01040001U cW01040001U) {
        mapper.delete(cW01040001U);
    }
}