package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jasamedika.medifirst2000.vo.PekerjaanVO;
import com.jasamedika.medifirst2000.vo.StatusKawinVO;

	import com.jasamedika.medifirst2000.entities.Pekerjaan;
import com.jasamedika.medifirst2000.entities.StatusKawin;


import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.DataKeluargaService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.JsonUtil;
import com.jasamedika.medifirst2000.entities.DataKeluarga;
import com.jasamedika.medifirst2000.vo.DataKeluargaVO;
import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.DataKeluargaDao;

/**
 * Implement class for DataKeluargaService
 * 
 * @author Generator
 * @param <T>
 */
@Service("dataKeluargaService")
public class DataKeluargaServiceImpl extends BaseVoServiceImpl implements DataKeluargaService 
{	
	@Autowired
	private BaseConverterImpl<DataKeluargaVO,DataKeluarga>dataKeluargaConverter;
	@Autowired
private BaseConverterImpl<PekerjaanVO,Pekerjaan>pekerjaanConverter;

@Autowired
private BaseConverterImpl<StatusKawinVO,StatusKawin>statusKawinConverter;


	@Autowired
	private DataKeluargaDao dataKeluargaDao;


	
	@Override
	public Map<String, Object> saveDataKeluarga(DataKeluargaVO vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		DataKeluarga model = new DataKeluarga();
		model = dataKeluargaConverter.transferVOToModel(vo,model);
		if (CommonUtil.isNotNullOrEmpty(vo.getPekerjaan()))
		{
				model.setPekerjaan(pekerjaanConverter.transferVOToModel(vo.getPekerjaan(), new Pekerjaan()));
		}
		if (CommonUtil.isNotNullOrEmpty(vo.getStatusKawin()))
		{
				model.setStatusKawin(statusKawinConverter.transferVOToModel(vo.getStatusKawin(), new StatusKawin()));
		}

		DataKeluarga resultDomain = dataKeluargaDao.save(model);
		if (CommonUtil.isNotNullOrEmpty(resultDomain)) {
			result.put("noRec", resultDomain.getNoRec());
		}

		return result;
	}



	@Override
	public List<Map<String, Object>> findAll() {
		return JsonUtil.ToMaps(dataKeluargaDao.findAll());
	}
}