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.google.gson.GsonBuilder;
import com.jasamedika.medifirst2000.converter.base.BaseVoConverter;
import com.jasamedika.medifirst2000.entities.Kecamatan;
import com.jasamedika.medifirst2000.vo.KecamatanVO;

/**
 * Converter class between Pasien and PasienVO
 * 
 * @author Askur
 */
@Component
public class KecamatanConverter implements BaseVoConverter<KecamatanVO, Kecamatan> {


	@Override
	public Kecamatan transferVOToModel(KecamatanVO vo, Kecamatan model) {
		if (null == model)
			model = new Kecamatan();

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

	@Override
	public List<KecamatanVO> transferListOfModelToListOfVO(List<Kecamatan> models, List<KecamatanVO> vos) {

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public KecamatanVO transferModelToVO(Kecamatan model, KecamatanVO vo) {
		if (null == vo)
			vo = new KecamatanVO();
		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, KecamatanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return vo;
	}
	
	
	
	

}
