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.PraAnestesiPasienHeader;
import com.jasamedika.medifirst2000.vo.PraAnestesiPasienHeaderVO;

@Component
public class PraAnestesiPasienHeaderConverter implements BaseVoConverter<PraAnestesiPasienHeaderVO, PraAnestesiPasienHeader> {
	@Override
	public PraAnestesiPasienHeader transferVOToModel(PraAnestesiPasienHeaderVO vo, PraAnestesiPasienHeader model) {
		if (null == model)
			model = new PraAnestesiPasienHeader();
		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, PraAnestesiPasienHeader.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return model;
	}

	@Override
	public List<PraAnestesiPasienHeaderVO> transferListOfModelToListOfVO(List<PraAnestesiPasienHeader> models, List<PraAnestesiPasienHeaderVO> vos) {

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

		if (null == models)
			return vos;

		for (PraAnestesiPasienHeader praAnestesiPasienHeader : models) {
			PraAnestesiPasienHeaderVO vo = new PraAnestesiPasienHeaderVO();
			vo=transferModelToVO(praAnestesiPasienHeader, vo);
			vos.add(vo);
		}

		return vos;
	}

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

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

		vo = new PraAnestesiPasienHeaderVO();

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

}
