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.PMAnamnesisUmum;
import com.jasamedika.medifirst2000.vo.PMAnamnesisUmumVO;

/**
 * @author Shakato
 *
 */
@Component
public class PMAnamnesisUmumConverter extends FindConverterDao implements BaseVoConverter<PMAnamnesisUmumVO, PMAnamnesisUmum>{

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

	@Override
	public List<PMAnamnesisUmumVO> transferListOfModelToListOfVO(List<PMAnamnesisUmum> models,
			List<PMAnamnesisUmumVO> vos) {
			if (vos == null) {
				vos = new ArrayList<PMAnamnesisUmumVO>();
			}
			
			if (models == null) {
				return vos;
			}
			
			for (PMAnamnesisUmum status : models) {
				PMAnamnesisUmumVO vo = new PMAnamnesisUmumVO();
				vo=transferModelToVO(status, vo);
				vos.add(vo);
			}
			return vos;
	}

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

		return vo;
	}

	

}
