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.Diagnosa;

import com.jasamedika.medifirst2000.vo.DiagnosaVO;

@Component
public class DiagnosaConverter implements BaseVoConverter<DiagnosaVO, Diagnosa> {


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

		return model;
	}

	@Override
	public List<DiagnosaVO> transferListOfModelToListOfVO(List<Diagnosa> models, List<DiagnosaVO> vos) {

		if (null == vos)
			vos = new ArrayList<DiagnosaVO>();

		if (null == models)
			return vos;

		for (Diagnosa diagnosa : models) {
			DiagnosaVO vo = new DiagnosaVO();
			vo=transferModelToVO(diagnosa, vo);
			vos.add(vo);
		}

		return vos;
	}

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

		return vo;
	}
	
	public DiagnosaVO transferModelToVOCustom(Diagnosa model, DiagnosaVO vo,String[] fieldsToInclude) {
		if (null == vo)

		vo = new DiagnosaVO();

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

}
