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.StrukRetur;
import com.jasamedika.medifirst2000.vo.StrukReturVO;

/**
 * Converter class between StrukRetur and StrukReturVO
 * 
 * @author Askur
 */
@Component
public class StrukReturConverter implements BaseVoConverter<StrukReturVO, StrukRetur> {
	

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

	}

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

		if (null == models)
			return vos;

		for (StrukRetur StrukRetur : models) {
			StrukReturVO vo = new StrukReturVO();
			vo = transferModelToVO(StrukRetur, vo);
			vos.add(vo);
		}

		return vos;
	}

	@Override
	public StrukReturVO transferModelToVO(StrukRetur model, StrukReturVO vo) {

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

		return vo;
	
	}

	
}
