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.PlanningPegawaiStatus;
import com.jasamedika.medifirst2000.vo.PlanningPegawaiStatusVO;

/**
 * Converter class between PlanningPegawaiStatus and PlanningPegawaiStatusVO
 * 
 * @author salmanoe
 */
@Component
public class PlanningPegawaiStatusConverter implements BaseVoConverter<PlanningPegawaiStatusVO, PlanningPegawaiStatus> {

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

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

		if (null == models)
			return vos;

		for (PlanningPegawaiStatus planningPegawaiStatus : models) {
			PlanningPegawaiStatusVO vo = new PlanningPegawaiStatusVO();
			vo = transferModelToVO(planningPegawaiStatus, vo);
			vos.add(vo);
		}

		return vos;
	}

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

		return vo;
	}

}
