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.AsuransiPasienDao;
import com.jasamedika.medifirst2000.dao.HubunganPesertaAsuransiDao;
import com.jasamedika.medifirst2000.dao.PegawaiDao;
import com.jasamedika.medifirst2000.dao.RekananDao;
import com.jasamedika.medifirst2000.dto.PesertaAsuransiBpjsNakerDto;
import com.jasamedika.medifirst2000.entities.AsuransiPasien;
import com.jasamedika.medifirst2000.service.PesertaAsuransiBpjsNakerService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.JsonUtil;

/**
 * Implement class for PekerjaanService
 * 
 * @author Generator
 * @param <T>
 */
@Service("pesertaAsuransiBpjsNakerService")
public class PesertaAsuransiBpjsNakerServiceImpl extends BaseVoServiceImpl implements PesertaAsuransiBpjsNakerService 
{	
	@Autowired
	private PegawaiDao pegawaiDao;

	@Autowired
	private RekananDao rekananDao;

	@Autowired
	private AsuransiPasienDao asuransiPasienDao;

	@Autowired
	private HubunganPesertaAsuransiDao hubunganPesertaAsuransiDao;

	@Override
	public Map<String, Object> save(PesertaAsuransiBpjsNakerDto vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		AsuransiPasien asuransiPasien=new AsuransiPasien();
		if(vo.getAsuransiPasienId()!=null){
			asuransiPasien.setId(vo.getAsuransiPasienId());
		}
		asuransiPasien.setPegawai(pegawaiDao.findOne(vo.getPegawaiId()));
		asuransiPasien.setRekanan(rekananDao.findOne(vo.getRekananAsuransiId()));
		asuransiPasien.setHubunganPeserta(hubunganPesertaAsuransiDao.findOne(vo.getHubunganPesertaId()));
		asuransiPasien.setNoAsuransi(vo.getNoKartuPolis());
		asuransiPasien.setNamaPeserta(vo.getNamaPesertaAsuransi());
		AsuransiPasien resultDomain = asuransiPasienDao.save(asuransiPasien);
		if (CommonUtil.isNotNullOrEmpty(resultDomain)) {
			try {
				result.put("data", JsonUtil.ToMapObject(asuransiPasien));
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	@Override
	public Map<String, Object> get(Integer asuransiId) {
		Map<String,Object> mapEmpty=new HashMap<String,Object>();
		Map<String,Object> map=asuransiPasienDao.get(asuransiId);
		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=asuransiPasienDao.getAll();
		if (CommonUtil.isNotNullOrEmpty(map)) {
			return map;
		}else{
			return mapEmpty;
		}
	}

	@Override
	public List<Map<String, Object>> getAllPegawai() {
		return pegawaiDao.findAllPegawais();
	}

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

	@Override
	public List<Map<String, Object>> getAllHubunganPeserta() {
		return hubunganPesertaAsuransiDao.findAllHubunganPesertaAsuransi();
	}
	
}