package sgc.portal.cw.cw1001.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.cw1001.dto.CW10010001USearch;
import sgc.portal.cw.cw1001.model.CW10010001U;
import sgc.portal.cw.cw1001.persistence.CW10010001UMapper;

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

@Service
public class CW10010001UService {
	
    private final CW10010001UMapper mapper;

    public CW10010001UService(CW10010001UMapper mapper) {
        this.mapper = mapper;
    }
    
    //잉여 자재(비품)정보 공유 (관리자) 조회
    public List<EasyHashMap<String, Object>> selectSiteAddress(CW10010001USearch search) {
        return mapper.selectSiteAddress(search);
    }
    
    //잉여 자재(비품)정보 공유 (관리자) 추가 수정 삭제
    @Transactional
    public Map<String, String> save (List<CW10010001U> CW10010001U) {
    	
    	Map<String,String> result = new HashMap<>();

        for (CW10010001U cW10010001U : CW10010001U) {
        	
            switch (cW10010001U.getRowStatus()) {
            
                case GridRowStatus.CREATED:
                	mapper.insertSiteAddress(cW10010001U);
                    break;
                    
                case GridRowStatus.UPDATED:
                	mapper.updateSiteAddress(cW10010001U);
                    break;
                    
                case GridRowStatus.DELETED:
                	mapper.deleteSiteAddress(cW10010001U);
                    break;
                default:
                    break;
            }
        }
        return result;
    }
}