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.PemeriksaanTriage;
import com.jasamedika.medifirst2000.vo.PemeriksaanTriageVO;

/**
 * 
 * @author Shakato
 */
@Component
public class PemeriksaanTriageConverter implements BaseVoConverter<PemeriksaanTriageVO, PemeriksaanTriage>{

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

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

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

		return vo;
	}

}
