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

import com.jasamedika.medifirst2000.vo.DiagnosaPasienVO;

@Component
public class DiagnosaPasienConverter implements BaseVoConverter<DiagnosaPasienVO, DiagnosaPasien> {


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

		return model;
	}

	@Override
	public List<DiagnosaPasienVO> transferListOfModelToListOfVO(List<DiagnosaPasien> models, List<DiagnosaPasienVO> vos) {

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

		if (null == models)
			return vos;

		for (DiagnosaPasien diagnosaPasien : models) {
			DiagnosaPasienVO vo = new DiagnosaPasienVO();
			vo=transferModelToVO(diagnosaPasien, vo);
			vos.add(vo);
		}

		return vos;
	}

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

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

		vo = new DiagnosaPasienVO();

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

}
