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.StokProdukGlobal;
import com.jasamedika.medifirst2000.vo.StokProdukGlobalVO;

@Component
public class StokProdukGlobalConverter implements BaseVoConverter<StokProdukGlobalVO, StokProdukGlobal> {


	@Override
	public StokProdukGlobal transferVOToModel(StokProdukGlobalVO vo, StokProdukGlobal model) {
		if (null == model)
			model = new StokProdukGlobal();

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

		return model;
	}

	@Override
	public List<StokProdukGlobalVO> transferListOfModelToListOfVO(List<StokProdukGlobal> models, List<StokProdukGlobalVO> vos) {

		if (null == vos)
			vos = new ArrayList<StokProdukGlobalVO>();

		if (null == models)
			return vos;

		for (StokProdukGlobal stokProdukGlobal : models) {
			StokProdukGlobalVO vo = new StokProdukGlobalVO();
			vo=transferModelToVO(stokProdukGlobal, vo);
			vos.add(vo);
		}

		return vos;
	}

	@Override
	public StokProdukGlobalVO transferModelToVO(StokProdukGlobal model, StokProdukGlobalVO vo) {
		if (null == vo)
			vo = new StokProdukGlobalVO();
		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, StokProdukGlobalVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return vo;
	}
	
	
	
	

}
