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.PapKeluhanTambahan;
import com.jasamedika.medifirst2000.vo.PapKeluhanTambahanVO;

/**
 * Converter class between PAPKeluhanTambahan and PAPKeluhanTambahanVO
 * 
 * @author Askur
 */
@Component
public class PapKeluhanTambahanConverter implements BaseVoConverter<PapKeluhanTambahanVO, PapKeluhanTambahan> {
	

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public PapKeluhanTambahanVO transferModelToVO(PapKeluhanTambahan model, PapKeluhanTambahanVO vo) {

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

		return vo;
	
	}

	
}
