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.PengendaliDao;
import com.jasamedika.medifirst2000.entities.Pengendali;
import com.jasamedika.medifirst2000.service.PengendaliService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.PengendaliVO;

@Service("pengendaliService")
public class PengendaliServiceImpl implements PengendaliService{
	
	@Autowired
	private PengendaliDao pengendaliDao;
	
	@Autowired
	private BaseConverterImpl<PengendaliVO, Pengendali> pengendaliConverter;

	@Override
	public Map<String, Object> savePengendali(PengendaliVO vo) {
		Pengendali pengendali = new Pengendali();
		Map<String,Object> result = new HashMap<String,Object>();
		
		if(CommonUtil.isNotNullOrEmpty(vo)){
			pengendali = pengendaliConverter.transferVOToModel(vo, new Pengendali());
		}
		
		if(CommonUtil.isNotNullOrEmpty(pengendali)){
			Pengendali resultPengendali = pengendaliDao.save(pengendali);
			result.put("kodePengendali", resultPengendali.getKodePengendali());
		}
		
		return result;
	}
	
	@Override
	public Map<String, Object> findAllPengendali() {
		Map<String, Object> result = new HashMap<String, Object>();
		List<Pengendali> resultModel = (List<Pengendali>) pengendaliDao.findAll();
		
		if (CommonUtil.isNotNullOrEmpty(resultModel)) {
			result.put("data", resultModel);
			result.put("dataFound", true);
		} else {
			result.put("dataFound", false);
		}
		return result;
	}
	
	

	
}
