package com.jasamedika.medifirst2000.service.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.KemenLembDao;
import com.jasamedika.medifirst2000.dao.OutputDao;
import com.jasamedika.medifirst2000.entities.Kegiatan;
import com.jasamedika.medifirst2000.entities.KemenLemb;
import com.jasamedika.medifirst2000.entities.Output;
import com.jasamedika.medifirst2000.service.OutputService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.KemenLembVO;
import com.jasamedika.medifirst2000.vo.OutputVO;

@Service("outputService")
public class OutputServiceImpl implements OutputService{

	@Autowired
	private OutputDao outputDao;
	
	@Autowired
	private BaseConverterImpl<OutputVO, Output> outputConverter;
	
	@Override
	public Map<String, Object> saveOutput(OutputVO vo) {
		Output output = new Output();
		Map<String,Object> result = new HashMap<String,Object>();
		
		if(CommonUtil.isNotNullOrEmpty(vo)){
			output = outputConverter.transferVOToModel(vo, new Output());
		}
		
		if(CommonUtil.isNotNullOrEmpty(output)){
			Output resultOutput = outputDao.save(output);
			result.put("kodeOutput", resultOutput.getKodeOutput());
		}
		
		return result;
	}
	
	@Override
	public Map<String, Object> findAllOutput() {
		Map<String, Object> result = new HashMap<String, Object>();
		List<Output> resultModel = (List<Output>) outputDao.findAll();
		
		if (CommonUtil.isNotNullOrEmpty(resultModel)) {
			result.put("data", resultModel);
			result.put("dataFound", true);
		} else {
			result.put("dataFound", false);
		}
		return result;
	}

}
