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.Lokasi;
import com.jasamedika.medifirst2000.vo.LokasiVO;

/**
 * Converter class between Pasien and PasienVO
 * 
 * @author Askur
 */
@Component
public class LokasiConverter implements BaseVoConverter<LokasiVO, Lokasi> {


	@Override
	public Lokasi transferVOToModel(LokasiVO vo, Lokasi model) {
		if (null == model)
			model = new Lokasi();

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

	@Override
	public List<LokasiVO> transferListOfModelToListOfVO(List<Lokasi> models, List<LokasiVO> vos) {

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

		if (null == models)
			return vos;

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

		return vos;
	}

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

		return vo;
	}
	
	
	
	

}
