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.AsalPeserta;
import com.jasamedika.medifirst2000.util.ExtendedSpringBeanUtil;
import com.jasamedika.medifirst2000.vo.AsalPesertaVO;

/**
 * Converter class between AsalPeserta and AsalPesertaVO
 * 
 * @author Lukman Hakim
 */
@Component
public class AsalPesertaConverter extends FindConverterDao implements
		BaseVoConverter<AsalPesertaVO, AsalPeserta> {

	public AsalPeserta transferVOToModel(AsalPesertaVO vo, AsalPeserta model) {
		if (null == model)
			model = new AsalPeserta();

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

	}

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

		if (null == models)
			return vos;

		for (AsalPeserta asalPeserta : models) {
			AsalPesertaVO asalPesertaVO = new AsalPesertaVO();
			transferModelToVO(asalPeserta, asalPesertaVO);
			vos.add(asalPesertaVO);
		}

		return vos;
	}

	public AsalPesertaVO transferModelToVO(AsalPeserta model, AsalPesertaVO vo) {
		if (null == vo)
			vo = new AsalPesertaVO();

		// fix this
		ExtendedSpringBeanUtil.copySpecificProperties(model, vo,
				new String[] { "asalPeserta", }, new String[] { "asalPeserta" });
//		LoginUserVO test = loginUserService.findById(new Integer(1));
//		System.out.println("tea = " + test.getKataSandi());
		return vo;
	}

}
