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.KomponenHargaDao;
import com.jasamedika.medifirst2000.dao.PegawaiSKAsuransiDao;
import com.jasamedika.medifirst2000.dao.RekananDao;
import com.jasamedika.medifirst2000.dao.RuanganDao;
import com.jasamedika.medifirst2000.dao.SuratKeputusanDao;
import com.jasamedika.medifirst2000.dto.PegawaiSkAsuransiDto;
import com.jasamedika.medifirst2000.entities.PegawaiSKAsuransi;
import com.jasamedika.medifirst2000.entities.SuratKeputusan;
import com.jasamedika.medifirst2000.service.PegawaiSKAsuransiService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.JsonUtil;

/**
 * Implement class for PekerjaanService
 * 
 * @author Generator
 * @param <T>
 */
@Service("pegawaiSKAsuransiService")
public class PegawaiSKAsuransiServiceImpl extends BaseVoServiceImpl implements PegawaiSKAsuransiService 
{	
	@Autowired
	private PegawaiSKAsuransiDao pegawaiSKAsuransiDao;

	@Autowired
	private SuratKeputusanDao suratKeputusanDao;

	@Autowired
	private RekananDao rekananDao;

	@Autowired
	private KomponenHargaDao komponenHargaDao;

	@Autowired
	private RuanganDao ruanganDao;

	@Override
	public Map<String, Object> save(PegawaiSkAsuransiDto vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		PegawaiSKAsuransi pegawaiSkAsuransi=new PegawaiSKAsuransi();
		if(vo.getPegawaiSkAsuransiId()!=null)
			pegawaiSkAsuransi.setId(vo.getPegawaiSkAsuransiId());
		SuratKeputusan suratKeputusan=new SuratKeputusan();
		if(vo.getSuratKeputusanId()!=null)
			suratKeputusan.setId(vo.getSuratKeputusanId());
		suratKeputusan.setNoSK(vo.getNoSuratKeputusan());
		suratKeputusan.setNamaSK(vo.getNamaSuratKeputusan());
		suratKeputusan.setTglBerlakuAwal(vo.getTglBerlakuAwal());
		suratKeputusan.setTglBerlakuAkhir(vo.getTglBerlakuAkhir());
		suratKeputusan.setRuangan(ruanganDao.findAllById(vo.getRuanganId()));
		SuratKeputusan resultSuratKeputusan=suratKeputusanDao.save(suratKeputusan);
		pegawaiSkAsuransi.setNoSK(resultSuratKeputusan);
		pegawaiSkAsuransi.setRekanan(rekananDao.findOne(vo.getRekananPenjaminAsuransiId()));
		pegawaiSkAsuransi.setKomponenHarga(komponenHargaDao.findOne(vo.getKomponenHargaId()));
		pegawaiSkAsuransi.setFactorRate(vo.getFactorRate());
		pegawaiSkAsuransi.setOperatorFactorRate(vo.getOperatorFactorRate());
		pegawaiSkAsuransi.setTotalFactorRatePremi(vo.getTotalFactorRatePremi());
		pegawaiSkAsuransi.setHargaSatuanPremi(vo.getHargaSatuanPremi());
		pegawaiSkAsuransi.setPersenHargaSatuanPremi(vo.getPersenPremi());
		pegawaiSkAsuransi.setIsByMonth(vo.getIsByMonth());
		pegawaiSkAsuransi.setIsByYear(vo.getIsByYear());
		pegawaiSkAsuransi.setStatusEnabled(vo.getStatusEnabled());
		PegawaiSKAsuransi resultDomain = pegawaiSKAsuransiDao.save(pegawaiSkAsuransi);
		if (CommonUtil.isNotNullOrEmpty(resultDomain)) {
			try {
				result.put("data", JsonUtil.ToMapObject(pegawaiSkAsuransi));
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}

		return result;
	}
	
	@Override
	public Map<String, Object> get(Integer pegawaiSkAsuransiId) {
		Map<String,Object> mapEmpty=new HashMap<String,Object>();
		Map<String,Object> map=pegawaiSKAsuransiDao.get(pegawaiSkAsuransiId);
		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=pegawaiSKAsuransiDao.getAll();
		if (CommonUtil.isNotNullOrEmpty(map)) {
			return map;
		}else{
			return mapEmpty;
		}
	}

	@Override
	public List<Map<String, Object>> getAllRuangan() {
		return ruanganDao.findAllRuangan();
	}

	@Override
	public List<Map<String, Object>> getAllRekanan() {
		return rekananDao.findAllRekanan();
	}

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

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