package com.jasamedika.medifirst2000.service.impl;

import java.util.HashMap;
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.JenisPengadaanDao;
import com.jasamedika.medifirst2000.entities.JenisPengadaan;
import com.jasamedika.medifirst2000.service.JenisPengadaanService;
import com.jasamedika.medifirst2000.vo.JenisPengadaanVO;

@Service("jenisPengadaanService")
public class JenisPengadaanServiceImpl implements JenisPengadaanService {

	@Autowired
	private JenisPengadaanDao jenisPengadaanDao;

	@Autowired
	private BaseConverterImpl<JenisPengadaanVO, JenisPengadaan> jenisPengadaanConverter;

	@Override
	public Map<String, Object> saveJenisPengadaan(JenisPengadaanVO vo) {

		Map<String, Object> result = new HashMap<String, Object>();

		try {
			System.out.println("==================START SAVE JENIS PENGADAAN======================");

			JenisPengadaan jenisPengadaan = jenisPengadaanConverter.transferVOToModel(vo, new JenisPengadaan());

			JenisPengadaan resultModel = jenisPengadaanDao.save(jenisPengadaan);
			result.put("id", resultModel.getId());
			System.out.println("==================END SAVE JENIS PENGADAAN======================");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

	@Override
	public Map<String, Object> updateJenisPengadaan(JenisPengadaanVO vo) {

		Map<String, Object> result = new HashMap<String, Object>();

		try {
			System.out.println("==================START UPDATE JENIS PENGADAAN======================");

			JenisPengadaan jenisPengadaan = jenisPengadaanConverter.transferVOToModel(vo, new JenisPengadaan());

			JenisPengadaan resultModel = jenisPengadaanDao.save(jenisPengadaan);
			result.put("id", resultModel.getId());
			System.out.println("==================END UPDATE JENIS PENGADAAN======================");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

}
