package sgc.portal.cw.cw1501.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.cw1501.model.CW15010001U;
import sgc.portal.cw.cw1501.dto.CW15010001USearch;
import sgc.portal.cw.cw1501.persistence.CW15010001UMapper;

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

@Service
public class CW15010001UService {
    private final CW15010001UMapper mapper;

    public CW15010001UService(CW15010001UMapper mapper) {
        this.mapper = mapper;
    }

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

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

    private void insert(CW15010001U cW15010001U) {
        mapper.insert(cW15010001U);
    }

    private void update(CW15010001U cW15010001U) {
        mapper.update(cW15010001U);
    }

    private void delete(CW15010001U cW15010001U) {
        mapper.delete(cW15010001U);
    }
    
    //디스플레이  수정삭체추가
    public  Map<String, String>  saveZherCarDisplAllList(CW15010001U cW15010001U) {
    	 
    	 Map<String,String> result = new HashMap<>();
    	 List<EasyHashMap<String, Object>> info = mapper.selectZherCarDisplList();
    	 mapper.updateZherCarDisplAll(cW15010001U);
    	 
    	 result.put("asSuccessCd", cW15010001U.getAsSuccessCd());
 		 result.put("asMessage", cW15010001U.getAsMessage());
 		 return result;
    }
}
