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.Soap;
import com.jasamedika.medifirst2000.vo.SoapVO;

/**
 * Converter class between Soap and SoapVO
 * 
 * @author Askur
 */
@Component
public class SoapConverter implements BaseVoConverter<SoapVO, Soap> {
	

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

	}

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

		if (null == models)
			return vos;

		for (Soap alamat : models) {
			SoapVO vo = new SoapVO();
			vo = transferModelToVO(alamat, vo);
			vos.add(vo);
		}

		return vos;
	}

	@Override
	public SoapVO transferModelToVO(Soap model, SoapVO vo) {

		if (null == vo)
			vo = new SoapVO();
		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, SoapVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return vo;
	
	}

	
}
