package com.jasamedika.medifirst2000.converter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.google.gson.Gson;
import com.jasamedika.medifirst2000.converter.base.BaseVoConverter;
import com.jasamedika.medifirst2000.dao.custom.base.impl.FindConverterDao;
import com.jasamedika.medifirst2000.entities.RiwayatKesehatan;
import com.jasamedika.medifirst2000.vo.RiwayatKesehatanVO;

/**
 * 
 * @author Shakato
 */
@Component
public class RiwayatKesehatanConverter extends FindConverterDao implements
		BaseVoConverter<RiwayatKesehatanVO, RiwayatKesehatan> {

	public RiwayatKesehatan transferVOToModel(RiwayatKesehatanVO vo, RiwayatKesehatan model) {
		if (null == model)
			model = new RiwayatKesehatan();
		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = vo.serialize(fieldsToInclude,vo.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        model = gson.fromJson(json, RiwayatKesehatan.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return model;

	}

	public List<RiwayatKesehatanVO> transferListOfModelToListOfVO(List<RiwayatKesehatan> models,
			List<RiwayatKesehatanVO> vos) {
		if (null == vos)
			vos = new ArrayList<RiwayatKesehatanVO>();

		if (null == models)
			return vos;

		for (RiwayatKesehatan riwayatKesehatan : models) {
			RiwayatKesehatanVO riwayatKesehatanVO = new RiwayatKesehatanVO();
			transferModelToVO(riwayatKesehatan, riwayatKesehatanVO);
			vos.add(riwayatKesehatanVO);
		}

		return vos;
	}

	public RiwayatKesehatanVO transferModelToVO(RiwayatKesehatan model, RiwayatKesehatanVO vo) {
		if (null == vo)

		vo = new RiwayatKesehatanVO();

		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, RiwayatKesehatanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}
	
	
	public RiwayatKesehatanVO transferModelToVOCustom(RiwayatKesehatan model, RiwayatKesehatanVO vo,String[] fieldsToInclude) {
		if (null == vo)

		vo = new RiwayatKesehatanVO();

		try {
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, RiwayatKesehatanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}

}
