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.PapRiwayatTumbuhKembang;
import com.jasamedika.medifirst2000.vo.PapRiwayatTumbuhKembangVO;

/**
 * Converter class between PAPRiwayatTumbuhKembang and PAPRiwayatTumbuhKembangVO
 * 
 * @author Askur
 */
@Component
public class PapRiwayatTumbuhKembangConverter implements BaseVoConverter<PapRiwayatTumbuhKembangVO, PapRiwayatTumbuhKembang> {
	

	public PapRiwayatTumbuhKembang transferVOToModel(PapRiwayatTumbuhKembangVO vo, PapRiwayatTumbuhKembang model) {
		if (null == model)
			model = new PapRiwayatTumbuhKembang();
		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, PapRiwayatTumbuhKembang.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return model;

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public PapRiwayatTumbuhKembangVO transferModelToVO(PapRiwayatTumbuhKembang model, PapRiwayatTumbuhKembangVO vo) {

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

		return vo;
	
	}

	
}
