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.PersepsiPasien;
import com.jasamedika.medifirst2000.vo.PersepsiPasienVO;

/**
 * Converter class between PersepsiPasien and PersepsiPasienVO
 * 
 * @author Askur
 */
@Component
public class PersepsiPasienConverter implements BaseVoConverter<PersepsiPasienVO, PersepsiPasien> {
	

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public PersepsiPasienVO transferModelToVO(PersepsiPasien model, PersepsiPasienVO vo) {

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

		return vo;
	
	}

	
}
