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.KelainanDetail;
import com.jasamedika.medifirst2000.vo.KelainanDetailVO;

/**
 * Converter class between KelainanDetailConverter
 * 
 * @author Askur
 */
@Component
public class KelainanDetailConverter implements BaseVoConverter<KelainanDetailVO, KelainanDetail> {
	

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public KelainanDetailVO transferModelToVO(KelainanDetail model, KelainanDetailVO vo) {

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

		return vo;
	
	}

	
}
