package sgc.portal.cw.cw0623.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.cw0623.model.CW06230001U;
import sgc.portal.cw.cw0623.dto.CW06230001USearch;
import sgc.portal.cw.cw0623.persistence.CW06230001UMapper;

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

@Service
public class CW06230001UService {
    private final CW06230001UMapper mapper;

    public CW06230001UService(CW06230001UMapper mapper) {
        this.mapper = mapper;
    }

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

    private void insert(CW06230001U cW06230001U) {

		int seq = mapper.selectSeq(cW06230001U);
		cW06230001U.setSeq(seq);
        mapper.insert(cW06230001U);
    }

    private void update(CW06230001U cW06230001U) {
        mapper.update(cW06230001U);
    }

    private void delete(CW06230001U cW06230001U) {
        mapper.delete(cW06230001U);
    }

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

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