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.PeranHubungan;
import com.jasamedika.medifirst2000.vo.PeranHubunganVO;

/**
 * Converter class between PeranHubungan and PeranHubunganVO
 * 
 * @author Askur
 */
@Component
public class PeranHubunganConverter implements BaseVoConverter<PeranHubunganVO, PeranHubungan> {
	

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public PeranHubunganVO transferModelToVO(PeranHubungan model, PeranHubunganVO vo) {

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

		return vo;
	
	}

	
}
