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.PapAssesmentGizi;
import com.jasamedika.medifirst2000.vo.PapAssesmentGiziVO;

/**
 * Converter class between PAPAssesmentGizi and PAPAssesmentGiziVO
 * 
 * @author Askur
 */
@Component
public class PapAssesmentGiziConverter implements BaseVoConverter<PapAssesmentGiziVO, PapAssesmentGizi> {
	

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

	}

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

		if (null == models)
			return vos;

		for (PapAssesmentGizi alamat : models) {
			PapAssesmentGiziVO vo = new PapAssesmentGiziVO();
			vo = transferModelToVO(alamat, vo);
			vos.add(vo);
		}

		return vos;
	}

	@Override
	public PapAssesmentGiziVO transferModelToVO(PapAssesmentGizi model, PapAssesmentGiziVO vo) {

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

		return vo;
	
	}

	
}
