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.entities.KemenLemb;
import com.jasamedika.medifirst2000.entities.Pengendali;
import com.jasamedika.medifirst2000.service.KemenLembService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.KemenLembVO;

@Service("kemenLembService")
public class KemenLembServiceImpl implements KemenLembService{

	@Autowired
	private KemenLembDao kemenLembDao;
	
	@Autowired
	private BaseConverterImpl<KemenLembVO, KemenLemb> kemenLembConverter;
	
	@Override
	public Map<String, Object> saveKemenLemb(KemenLembVO vo) {
		KemenLemb kemenLemb = new KemenLemb();
		Map<String,Object> result = new HashMap<String,Object>();
		
		if(CommonUtil.isNotNullOrEmpty(vo)){
			kemenLemb = kemenLembConverter.transferVOToModel(vo, new KemenLemb());
		}
		
		if(CommonUtil.isNotNullOrEmpty(kemenLemb)){
			KemenLemb resultKemenLemb = kemenLembDao.save(kemenLemb);
			result.put("kodeKemenLemb", resultKemenLemb.getKodeKemenLemb());
		}
		
		return result;
	}
	
	@Override
	public Map<String, Object> findAllKemenLemb() {
		Map<String, Object> result = new HashMap<String, Object>();
		List<KemenLemb> resultModel = (List<KemenLemb>) kemenLembDao.findAll();
		
		if (CommonUtil.isNotNullOrEmpty(resultModel)) {
			result.put("data", resultModel);
			result.put("dataFound", true);
		} else {
			result.put("dataFound", false);
		}
		return result;
	}
	
	@Override
	public Map<String, Object> findOneKemenLemb() {
		Map<String, Object> result = new HashMap<String, Object>();
		KemenLemb resultModel = kemenLembDao.findOneKemenLemb("024");
		
		if (CommonUtil.isNotNullOrEmpty(resultModel)) {
			result.put("data", resultModel);
			result.put("dataFound", true);
		} else {
			result.put("dataFound", false);
		}
		return result;
	}

}
