package sgc.portal.ll.ll0101.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

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.ll.ll0101.dto.LL01010001USearch;
import sgc.portal.ll.ll0101.model.LL01010001U;
import sgc.portal.ll.ll0101.persistence.LL01010001UMapper;

@Service
public class LL01010001UService {

	private final LL01010001UMapper mapper;
	
    public LL01010001UService(LL01010001UMapper mapper) {
        this.mapper = mapper;
    }
	
    /**
     * Lessons Learned 조회
     * @param search
     * @return
     */
	public List<EasyHashMap<String, Object>> selectLlInfoList(LL01010001USearch search) {
		return mapper.selectLlInfoList(search);
	}

	public List<EasyHashMap<String, Object>> getAuthData(LL01010001USearch search) {
		return mapper.getAuthData(search);
	}
	
    @Transactional
    public Map<String, String> save(List<LL01010001U> LL01010001U) {
    	
    	Map<String,String> result = new HashMap<>();
    	
    	for (LL01010001U lL01010001U : LL01010001U) {
            switch (lL01010001U.getRowStatus()) {
                case GridRowStatus.CREATED:
            		int seq = mapper.selectSeq(lL01010001U);
            		lL01010001U.setSeq(seq);
                    insert(lL01010001U);
                    break;
                case GridRowStatus.UPDATED:
                    update(lL01010001U);
                    break;
                case GridRowStatus.DELETED:
                    delete(lL01010001U);
                    break;
                default:
                    break;
            }
        }
    	return result;
    }

    private void insert(LL01010001U lL01010001U) {
        mapper.insertLlInfo(lL01010001U);
    }

    private void update(LL01010001U lL01010001U) {
        mapper.updateLlInfo(lL01010001U);
    }

    private void delete(LL01010001U lL01010001U) {
        mapper.deleteLlInfo(lL01010001U);
    }

}
