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.TimeOutControl;
import com.jasamedika.medifirst2000.vo.TimeOutControlVO;

@Component
public class TimeOutControlConverter implements BaseVoConverter<TimeOutControlVO, TimeOutControl>{

	@Override
	public TimeOutControl transferVOToModel(TimeOutControlVO vo, TimeOutControl model) {

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

		return model;
	}

	@Override
	public List<TimeOutControlVO> transferListOfModelToListOfVO(List<TimeOutControl> models,
			List<TimeOutControlVO> vos) {

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

		if (null == models)
			return vos;

		for (TimeOutControl timeOutControl : models) {
			TimeOutControlVO vo = new TimeOutControlVO();
			vo=transferModelToVO(timeOutControl, vo);
			vos.add(vo);
		}

		return vos;
	}

	@Override
	public TimeOutControlVO transferModelToVO(TimeOutControl model, TimeOutControlVO vo) {

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

		return vo;
	}

}
