package sgc.portal.cw.cw0622.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.cw0622.model.CW06220001U;
import sgc.portal.cw.cw0622.dto.CW06220001USearch;
import sgc.portal.cw.cw0622.persistence.CW06220001UMapper;

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

@Service
public class CW06220001UService {
    private final CW06220001UMapper mapper;

    public CW06220001UService(CW06220001UMapper mapper) {
        this.mapper = mapper;
    }

    public List<EasyHashMap<String, Object>> getList(CW06220001USearch search) {
        return mapper.getList(search);
    }
    
    @Transactional
    public Map<String, String> save(List<CW06220001U> CW06220001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (CW06220001U cW06220001U : CW06220001U) {
            switch (cW06220001U.getRowStatus()) {
                case GridRowStatus.CREATED:
                    insert(cW06220001U);
                    break;
                case GridRowStatus.UPDATED:
                    update(cW06220001U);
                    break;
                case GridRowStatus.DELETED:
                    delete(cW06220001U);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }

    private void insert(CW06220001U cW06220001U) {
        mapper.insert(cW06220001U);
    }

    private void update(CW06220001U cW06220001U) {
        mapper.update(cW06220001U);
    }

    private void delete(CW06220001U cW06220001U) {
        mapper.delete(cW06220001U);
    }
}
