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.StrukOrder;
import com.jasamedika.medifirst2000.vo.PapPernapasanVO;

/**
 * Converter class PAPPernapasan
 * 
 * @author Askur
 */
@Component
public class StrukOrderConverter extends FindConverterDao implements
		BaseVoConverter<PapPernapasanVO, StrukOrder> {

	public StrukOrder transferVOToModel(PapPernapasanVO vo, StrukOrder model) {
		if (null == model)
			model = new StrukOrder();

		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, StrukOrder.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return model;

	}

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

		if (null == models)
			return vos;

		for (StrukOrder model : models) {
			PapPernapasanVO vo = new PapPernapasanVO();
			transferModelToVO(model, vo);
			vos.add(vo);
		}

		return vos;
	}

	public PapPernapasanVO transferModelToVO(StrukOrder model, PapPernapasanVO vo) {
		if (null == vo)
			vo = new PapPernapasanVO();

		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, PapPernapasanVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}
	
}
