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.KasusPenyakit;
import com.jasamedika.medifirst2000.vo.KasusPenyakitVO;

/**
 * Converter class between Pasien and PasienVO
 * 
 * @author Askur
 */
@Component
public class KasusPenyakitConverter implements BaseVoConverter<KasusPenyakitVO, KasusPenyakit> {


	@Override
	public KasusPenyakit transferVOToModel(KasusPenyakitVO vo, KasusPenyakit model) {
		if (null == model)
			model = new KasusPenyakit();

		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, KasusPenyakit.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return model;
	}

	@Override
	public List<KasusPenyakitVO> transferListOfModelToListOfVO(List<KasusPenyakit> models, List<KasusPenyakitVO> vos) {

		if (null == vos)
			vos = new ArrayList<KasusPenyakitVO>();

		if (null == models)
			return vos;

		for (KasusPenyakit pegawai : models) {
			KasusPenyakitVO vo = new KasusPenyakitVO();
			vo=transferModelToVO(pegawai, vo);
			vos.add(vo);
		}

		return vos;
	}

	@Override
	public KasusPenyakitVO transferModelToVO(KasusPenyakit model, KasusPenyakitVO vo) {
		if (null == vo)
			vo = new KasusPenyakitVO();
		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, KasusPenyakitVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}
	
	
	
	

}
