package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
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.dao.JabatanDao;
import com.jasamedika.medifirst2000.dao.KomponenHargaDao;
import com.jasamedika.medifirst2000.dao.PegawaiStrukturGajiByJaPeDao;
import com.jasamedika.medifirst2000.dao.PendidikanDao;
import com.jasamedika.medifirst2000.dto.PegawaiStrukturGajiByJaPeDto;
import com.jasamedika.medifirst2000.entities.PegawaiStrukturGajiByJaPe;
import com.jasamedika.medifirst2000.service.PegawaiStrukturGajiByJaPeService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.JsonUtil;

@Service("PegawaiStrukturGajiByJaPeService")
public class PegawaiStrukturGajiByJaPeServiceImpl extends BaseVoServiceImpl implements PegawaiStrukturGajiByJaPeService 
{	
	@Autowired
	private PegawaiStrukturGajiByJaPeDao pegawaiStrukturGajiByJaPeDao;

	@Autowired
	private KomponenHargaDao komponenHargaDao;
	
	@Autowired
	private JabatanDao jabatanDao;

	@Autowired
	private PendidikanDao pendidikanDao;

	@Override
	public Map<String, Object> save(PegawaiStrukturGajiByJaPeDto vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		PegawaiStrukturGajiByJaPe jape=new PegawaiStrukturGajiByJaPe();
		if(vo.getId()!=null){
			jape.setId(vo.getId());
		}
		jape.setJabatan(jabatanDao.findOne(vo.getJabatanId()));
		jape.setPendidikan(pendidikanDao.findOne(vo.getPendidikanId()));
		jape.setKomponenHarga(komponenHargaDao.findOne(vo.getKomponenHargaId()));
		jape.setKdProfile(vo.getKdProfile());
		jape.setHargaSatuan(vo.getHargaSatuan());
		jape.setFactorRate(vo.getFactorRate());
		jape.setOperatorFactorRate(vo.getOperatorFactorRate());
		jape.setStatusEnabled(vo.getStatusEnabled());
		PegawaiStrukturGajiByJaPe resultDomain = pegawaiStrukturGajiByJaPeDao.save(jape);
		if (CommonUtil.isNotNullOrEmpty(resultDomain)) {
			try {
				result.put("data", JsonUtil.ToMapObject(jape));
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}


		return result;
	}
	
	@Override
	public Map<String, Object> get(Integer pegawaiStrukturGajiByJaPeId) {
		Map<String,Object> mapEmpty=new HashMap<String,Object>();
		Map<String,Object> map=pegawaiStrukturGajiByJaPeDao.get(pegawaiStrukturGajiByJaPeId);
		if (CommonUtil.isNotNullOrEmpty(map)) {
			return map;
		}else{
			return mapEmpty;
		}
	}

	@Override
	public List<Map<String, Object>> getAll() {
		List<Map<String,Object>> mapEmpty=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> map=pegawaiStrukturGajiByJaPeDao.getAll();
		if (CommonUtil.isNotNullOrEmpty(map)) {
			return map;
		}else{
			return mapEmpty;
		}
	}

	@Override
	public List<Map<String, Object>> getAllKomponenHarga() {
		return komponenHargaDao.findAllKomponenHarga();
	}

	@Override
	public List<Map<String, Object>> getKomponenHargaByJenis(Integer idKomponenHarga) {
		return komponenHargaDao.findKomponenByJenis(idKomponenHarga);
	}

	@Override
	public List<Map<String, Object>> getAllJabatan() {
		return jabatanDao.findAllJabatan();
	}

	@Override
	public List<Map<String, Object>> getAllPendidikan() {
		return pendidikanDao.findAllPendidikan();
	}
}