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.dao.custom.base.impl.FindConverterDao;
import com.jasamedika.medifirst2000.entities.RiwayatPelatihan;
import com.jasamedika.medifirst2000.vo.RiwayatPelatihanVO;

/**
 * 
 * @author shakato
 */
@Component
public class RiwayatPelatihanConverter extends FindConverterDao implements
		BaseVoConverter<RiwayatPelatihanVO, RiwayatPelatihan> {

	public RiwayatPelatihan transferVOToModel(RiwayatPelatihanVO vo, RiwayatPelatihan model) {
		if (null == model)
			model = new RiwayatPelatihan();

		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = vo.serialize(fieldsToInclude,vo.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        model = gson.fromJson(json, RiwayatPelatihan.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return model;

	}

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

		if (null == models)
			return vos;

		for (RiwayatPelatihan model : models) {
			RiwayatPelatihanVO vo = new RiwayatPelatihanVO();
			transferModelToVO(model, vo);
			vos.add(vo);
		}

		return vos;
	}

	public RiwayatPelatihanVO transferModelToVO(RiwayatPelatihan model, RiwayatPelatihanVO vo) {
		if (null == vo)
			vo = new RiwayatPelatihanVO();

		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = model.serialize(fieldsToInclude,"RiwayatPelatihan");
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, RiwayatPelatihanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}
	
}
