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.DetailTriase;
import com.jasamedika.medifirst2000.vo.DetailTriaseVO;

/**
 * 
 * @author Shakato
 */
@Component
public class DetailTriaseConverter implements BaseVoConverter<DetailTriaseVO, DetailTriase>{

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

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

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

		return vo;
	}

}
