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.PegawaiStrukturGajiByJaDao;
import com.jasamedika.medifirst2000.dto.PegawaiStrukturGajiByJaDto;
import com.jasamedika.medifirst2000.entities.PegawaiStrukturGajiByJa;
import com.jasamedika.medifirst2000.service.PegawaiStrukturGajiByJaService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.JsonUtil;

@Service("PegawaiStrukturGajiByJaService")
public class PegawaiStrukturGajiByJaServiceImpl extends BaseVoServiceImpl implements PegawaiStrukturGajiByJaService 
{	
	@Autowired
	private PegawaiStrukturGajiByJaDao pegawaiStrukturGajiByJaDao;

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

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


		return result;
	}
	
	@Override
	public Map<String, Object> get(Integer pegawaiStrukturGajiByJaId) {
		Map<String,Object> mapEmpty=new HashMap<String,Object>();
		Map<String,Object> map=pegawaiStrukturGajiByJaDao.get(pegawaiStrukturGajiByJaId);
		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=pegawaiStrukturGajiByJaDao.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();
	}

}