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.entities.PapRiwayatImunisasi;
import com.jasamedika.medifirst2000.vo.PapRiwayatImunisasiVO;

/**
 * Converter class between PAPRiwayatImunisasi and PAPRiwayatImunisasiVO
 * 
 * @author Askur
 */
@Component
public class PapRiwayatImunisasiConverter implements BaseVoConverter<PapRiwayatImunisasiVO, PapRiwayatImunisasi> {
	

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

	}

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

		if (null == models)
			return vos;

		for (PapRiwayatImunisasi PapRiwayatImunisasi : models) {
			PapRiwayatImunisasiVO vo = new PapRiwayatImunisasiVO();
			vo = transferModelToVO(PapRiwayatImunisasi, vo);
			vos.add(vo);
		}

		return vos;
	}

	@Override
	public PapRiwayatImunisasiVO transferModelToVO(PapRiwayatImunisasi model, PapRiwayatImunisasiVO vo) {

		if (null == vo)
			vo = new PapRiwayatImunisasiVO();
		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, PapRiwayatImunisasiVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return vo;
	
	}

	
}
