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

/**
 * Converter class between PenangananKasus and PenangananKasusVO
 * 
 * @author Lukman Hakim
 */
@Component
public class PenangananKasusConverter extends FindConverterDao implements
		BaseVoConverter<PenangananKasusVO, PenangananKasus> {
	
	public PenangananKasus transferVOToModel(PenangananKasusVO vo, PenangananKasus model) {
		if (null == model)
			model = new PenangananKasus();

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

	}

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

		if (null == models)
			return vos;

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

		return vos;
	}

	public PenangananKasusVO transferModelToVO(PenangananKasus model, PenangananKasusVO vo) {
		if (null == vo)
			vo = new PenangananKasusVO();

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

}
