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.PersepsiKognisi;
import com.jasamedika.medifirst2000.vo.PersepsiKognisiVO;

/**
 * Converter class between PersepsiKognisi and PersepsiKognisiVO
 * 
 * @author Askur
 */
@Component
public class PersepsiKognisiConverter implements BaseVoConverter<PersepsiKognisiVO, PersepsiKognisi> {
	

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public PersepsiKognisiVO transferModelToVO(PersepsiKognisi model, PersepsiKognisiVO vo) {

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

		return vo;
	
	}

	
}
