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.NilaiNilai;
import com.jasamedika.medifirst2000.vo.NilaiNilaiVO;

/**
 * Converter class between NilaiNilai and NilaiNilaiVO
 * 
 * @author Askur
 */
@Component
public class NilaiNilaiConverter implements BaseVoConverter<NilaiNilaiVO, NilaiNilai> {
	

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public NilaiNilaiVO transferModelToVO(NilaiNilai model, NilaiNilaiVO vo) {

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

		return vo;
	
	}

	
}
