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.JadwalDokter;
import com.jasamedika.medifirst2000.vo.JadwalDokter_VO;

@Component
public class JadwalDokterConverter implements BaseVoConverter<JadwalDokter_VO,JadwalDokter>{

	@Override
	public JadwalDokter transferVOToModel(JadwalDokter_VO vo, JadwalDokter model) {
		if (null == model)
			model = new JadwalDokter();

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

	@Override
	public List<JadwalDokter_VO> transferListOfModelToListOfVO(List<JadwalDokter> models, List<JadwalDokter_VO> vos) {
		if (null == vos)
			vos = new ArrayList<JadwalDokter_VO>();

		if (null == models)
			return vos;

		for (JadwalDokter model : models) {
			JadwalDokter_VO vo = new JadwalDokter_VO();
			transferModelToVO(model, vo);
			vos.add(vo);
		}

		return vos;
	}

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

		return vo;
	}
	

}
