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.dao.custom.base.impl.FindConverterDao;
import com.jasamedika.medifirst2000.entities.PernahDirawatDetail;
import com.jasamedika.medifirst2000.vo.PernahDirawatDetailVO;

/**
 * 
 * @author Shakato
 */
@Component
public class PernahDirawatDetailConverter extends FindConverterDao implements
		BaseVoConverter<PernahDirawatDetailVO, PernahDirawatDetail> {

	public PernahDirawatDetail transferVOToModel(PernahDirawatDetailVO vo, PernahDirawatDetail model) {
		if (null == model)
			model = new PernahDirawatDetail();
		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = vo.serialize(fieldsToInclude,vo.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        model = gson.fromJson(json, PernahDirawatDetail.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return model;

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	public PernahDirawatDetailVO transferModelToVO(PernahDirawatDetail model, PernahDirawatDetailVO vo) {
		if (null == vo)

		vo = new PernahDirawatDetailVO();

		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, PernahDirawatDetailVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}
	
	
	public PernahDirawatDetailVO transferModelToVOCustom(PernahDirawatDetail model, PernahDirawatDetailVO vo,String[] fieldsToInclude) {
		if (null == vo)

		vo = new PernahDirawatDetailVO();

		try {
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, PernahDirawatDetailVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}

}
