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.PapDataTandaVital;
import com.jasamedika.medifirst2000.vo.PapDataTandaVitalVO;

/**
 * Converter class between PAPDataTandaVital and PAPDataTandaVitalVO
 * 
 * @author Askur
 */
@Component
public class PapDataTandaVitalConverter implements BaseVoConverter<PapDataTandaVitalVO, PapDataTandaVital> {
	

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public PapDataTandaVitalVO transferModelToVO(PapDataTandaVital model, PapDataTandaVitalVO vo) {

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

		return vo;
	
	}

	
}
