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.TingkatKelulusan;
import com.jasamedika.medifirst2000.vo.TingkatKelulusanVO;

/**
 * 
 * @author Shakato
 */
@Component
public class TingkatKelulusanConverter implements BaseVoConverter<TingkatKelulusanVO, TingkatKelulusan>{

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

	@Override
	public List<TingkatKelulusanVO> transferListOfModelToListOfVO(List<TingkatKelulusan> models,
		List<TingkatKelulusanVO> vos) {
		if (vos == null) {
			vos = new ArrayList<TingkatKelulusanVO>();
		}
		
		if (models == null) {
			return vos;
		}
		
		for (TingkatKelulusan status : models) {
			TingkatKelulusanVO vo = new TingkatKelulusanVO();
			vo=transferModelToVO(status, vo);
			vos.add(vo);
		}
		return vos;
	}

	@Override
	public TingkatKelulusanVO transferModelToVO(TingkatKelulusan model, TingkatKelulusanVO vo) {
		if (vo == null)
			vo = new TingkatKelulusanVO();
		try {
			String[] fieldsToInclude = {"tingkatKelulusan","tingkatKelulusan"};
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, TingkatKelulusanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return vo;
	}

}
