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.CatatanPerkembangan;
import com.jasamedika.medifirst2000.vo.CatatanPerkembanganVO;

@Component
public class CatatanPerkembanganConverter implements BaseVoConverter<CatatanPerkembanganVO, CatatanPerkembangan>{

	@Override
	public CatatanPerkembangan transferVOToModel(CatatanPerkembanganVO vo, CatatanPerkembangan model) {
		if (null == model)
			model = new CatatanPerkembangan();

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

		return model;
	}

	@Override
	public List<CatatanPerkembanganVO> transferListOfModelToListOfVO(List<CatatanPerkembangan> models,
			List<CatatanPerkembanganVO> vos) {
		if (null == vos)
			vos = new ArrayList<CatatanPerkembanganVO>();

		if (null == models)
			return vos;

		for (CatatanPerkembangan model : models) {
			CatatanPerkembanganVO vo = new CatatanPerkembanganVO();
			transferModelToVO(model, vo);
			vos.add(vo);
		}

		return vos;
	}

	@Override
	public CatatanPerkembanganVO transferModelToVO(CatatanPerkembangan model, CatatanPerkembanganVO vo) {
		if (null == vo)
			vo = new CatatanPerkembanganVO();

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

}
