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.dao.custom.base.impl.FindConverterDao;
import com.jasamedika.medifirst2000.entities.SatuanHasil;
import com.jasamedika.medifirst2000.util.ExtendedSpringBeanUtil;
import com.jasamedika.medifirst2000.vo.SatuanHasilVO;

/**
 * Converter class between SatuanHasil and SatuanHasilVO
 * 
 * @author Lukman Hakim
 */
@Component
public class SatuanHasilConverter extends FindConverterDao implements
		BaseVoConverter<SatuanHasilVO, SatuanHasil> {

	public SatuanHasil transferVOToModel(SatuanHasilVO vo, SatuanHasil model) {
		if (null == model)
			model = new SatuanHasil();

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

	}

	public List<SatuanHasilVO> transferListOfModelToListOfVO(List<SatuanHasil> models,
			List<SatuanHasilVO> vos) {
		if (null == vos)
			vos = new ArrayList<SatuanHasilVO>();

		if (null == models)
			return vos;

		for (SatuanHasil agama : models) {
			SatuanHasilVO agamaVO = new SatuanHasilVO();
			transferModelToVO(agama, agamaVO);
			vos.add(agamaVO);
		}

		return vos;
	}

	public SatuanHasilVO transferModelToVO(SatuanHasil model, SatuanHasilVO vo) {
		if (null == vo)
			vo = new SatuanHasilVO();

		// fix this
		ExtendedSpringBeanUtil.copySpecificProperties(model, vo,
				new String[] { "SatuanHasil", }, new String[] { "SatuanHasil" });
 
		return vo;
	}
	 

}
