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.KategoriHasilTriase;
import com.jasamedika.medifirst2000.vo.KategoriHasilTriaseVO;

/**
 * 
 * @author Shakato
 */
@Component
public class KategoriHasilTriaseConverter implements BaseVoConverter<KategoriHasilTriaseVO, KategoriHasilTriase>{

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

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

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

		return vo;
	}

}
