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.PapImunisasiDetail;
import com.jasamedika.medifirst2000.vo.PapImunisasiDetailVO;

/**
 * Converter class between PAPImunisasiDetail and PAPImunisasiDetailVO
 * 
 * @author Askur
 */
@Component
public class PapImunisasiDetailConverter implements BaseVoConverter<PapImunisasiDetailVO, PapImunisasiDetail> {
	

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public PapImunisasiDetailVO transferModelToVO(PapImunisasiDetail model, PapImunisasiDetailVO vo) {

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

		return vo;
	
	}

	
}
