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

import com.jasamedika.medifirst2000.vo.PreskripsiDietVO;

@Component
public class PreskripsiDietConverter implements BaseVoConverter<PreskripsiDietVO, PreskripsiDiet> {


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

		return model;
	}

	@Override
	public List<PreskripsiDietVO> transferListOfModelToListOfVO(List<PreskripsiDiet> models, List<PreskripsiDietVO> vos) {

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

		if (null == models)
			return vos;

		for (PreskripsiDiet preskripsiDiet : models) {
			PreskripsiDietVO vo = new PreskripsiDietVO();
			vo=transferModelToVO(preskripsiDiet, vo);
			vos.add(vo);
		}

		return vos;
	}

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

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

		vo = new PreskripsiDietVO();

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

}
