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.Ruangan;

import com.jasamedika.medifirst2000.vo.RuanganVO;

@Component
public class RuanganTindakLanjutGiziConverter implements BaseVoConverter<RuanganVO, Ruangan> {


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

		return model;
	}

	@Override
	public List<RuanganVO> transferListOfModelToListOfVO(List<Ruangan> models, List<RuanganVO> vos) {

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

		if (null == models)
			return vos;

		for (Ruangan ruangan : models) {
			RuanganVO vo = new RuanganVO();
			vo=transferModelToVO(ruangan, vo);
			vos.add(vo);
		}

		return vos;
	}

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

		return vo;
	}
	
	public RuanganVO transferModelToVOCustom(Ruangan model, RuanganVO vo,String[] fieldsToInclude) {
		if (null == vo)

		vo = new RuanganVO();

		try {
			Map<String, Object> serialized = model.serialize(fieldsToInclude,model.getClass().getSimpleName());
			Gson gson = new Gson();
	        String json = gson.toJson(serialized);
	        vo = gson.fromJson(json, RuanganVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}
	
	
	
	

}
