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.PapRehabilitasi;
import com.jasamedika.medifirst2000.vo.PapRehabilitasiVO;

/**
 * Converter class between PAPRehabilitasi and PAPRehabilitasiVO
 * 
 * @author Askur
 */
@Component
public class PapRehabilitasiConverter implements BaseVoConverter<PapRehabilitasiVO, PapRehabilitasi> {
	

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public PapRehabilitasiVO transferModelToVO(PapRehabilitasi model, PapRehabilitasiVO vo) {

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

		return vo;
	
	}

	
}
