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

import com.jasamedika.medifirst2000.vo.DetailDiagnosaPasienVO;

@Component
public class DetailDiagnosaPasienConverter implements BaseVoConverter<DetailDiagnosaPasienVO, DetailDiagnosaPasien> {


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

		return model;
	}

	@Override
	public List<DetailDiagnosaPasienVO> transferListOfModelToListOfVO(List<DetailDiagnosaPasien> models, List<DetailDiagnosaPasienVO> vos) {

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

		if (null == models)
			return vos;

		for (DetailDiagnosaPasien detailDiagnosaPasien : models) {
			DetailDiagnosaPasienVO vo = new DetailDiagnosaPasienVO();
			vo=transferModelToVO(detailDiagnosaPasien, vo);
			vos.add(vo);
		}

		return vos;
	}

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

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

		vo = new DetailDiagnosaPasienVO();

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

}
