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.JenisDiet;

import com.jasamedika.medifirst2000.vo.JenisDietVO;

@Component
public class JenisDietConverter implements BaseVoConverter<JenisDietVO, JenisDiet> {


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

		return model;
	}

	@Override
	public List<JenisDietVO> transferListOfModelToListOfVO(List<JenisDiet> models, List<JenisDietVO> vos) {

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

		if (null == models)
			return vos;

		for (JenisDiet jenisDiet : models) {
			JenisDietVO vo = new JenisDietVO();
			vo=transferModelToVO(jenisDiet, vo);
			vos.add(vo);
		}

		return vos;
	}

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

		return vo;
	}
	
	public JenisDietVO transferModelToVOCustom(JenisDiet model, JenisDietVO vo,String[] fieldsToInclude) {
		if (null == vo)

		vo = new JenisDietVO();

		try {
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, JenisDietVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}
	
	
	
	

}
