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.Inseminasi;
import com.jasamedika.medifirst2000.vo.InseminasiVO;

@Component
public class InseminasiConverter implements BaseVoConverter<InseminasiVO, Inseminasi>{

	@Override
	public Inseminasi transferVOToModel(InseminasiVO vo, Inseminasi model) {
		if (null == model)
			model = new Inseminasi();

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

		return model;
	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public InseminasiVO transferModelToVO(Inseminasi model, InseminasiVO vo) {
		if (null == vo)
			vo = new InseminasiVO();

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

}
