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.PapTransaksiEdukasi;
import com.jasamedika.medifirst2000.vo.PapTransaksiEdukasiVO;

@Component
public class PapTransaksiEdukasiConverter implements BaseVoConverter<PapTransaksiEdukasiVO, PapTransaksiEdukasi> {

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

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

		if (null == models)
			return vos;

		for (PapTransaksiEdukasi papTransaksinEdukasi : models) {
			PapTransaksiEdukasiVO vo = new PapTransaksiEdukasiVO();
			vo = transferModelToVO(papTransaksinEdukasi, vo);
			vos.add(vo);
		}

		return vos;
	}

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

		return vo;
	}

}
