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.google.gson.GsonBuilder;
import com.jasamedika.medifirst2000.converter.base.BaseVoConverter;
import com.jasamedika.medifirst2000.dao.custom.base.impl.FindConverterDao;
import com.jasamedika.medifirst2000.entities.HasilTriase;
import com.jasamedika.medifirst2000.vo.HasilTriaseVO;

/**
 * 
 * @author Shakato
 */
@Component
public class HasilTriaseConverter extends FindConverterDao implements
		BaseVoConverter<HasilTriaseVO, HasilTriase> {

	public HasilTriase transferVOToModel(HasilTriaseVO vo, HasilTriase model) {
		if (null == model)
			model = new HasilTriase();
		try {
			Gson gson = new GsonBuilder()//.excludeFieldsWithoutExposeAnnotation()
		            .setDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
		            .create();
	        String json = gson.toJson(vo.ToMap());
	        model = gson.fromJson(json, HasilTriase.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return model;

	}

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

		if (null == models)
			return vos;

		for (HasilTriase hasilTriase : models) {
			HasilTriaseVO hasilTriaseVO = new HasilTriaseVO();
			transferModelToVO(hasilTriase, hasilTriaseVO);
			vos.add(hasilTriaseVO);
		}

		return vos;
	}

	public HasilTriaseVO transferModelToVO(HasilTriase model, HasilTriaseVO vo) {
		if (null == vo)

		vo = new HasilTriaseVO();

		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson  =new GsonBuilder()//.excludeFieldsWithoutExposeAnnotation()
		            .setDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
		            .create();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, HasilTriaseVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}
	
	
	public HasilTriaseVO transferModelToVOCustom(HasilTriase model, HasilTriaseVO vo,String[] fieldsToInclude) {
		if (null == vo)

		vo = new HasilTriaseVO();

		try {
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson =new GsonBuilder()//.excludeFieldsWithoutExposeAnnotation()
		            .setDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
		            .create();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, HasilTriaseVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}

}
