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.ProdukDetailLaboratoriumHasil;
import com.jasamedika.medifirst2000.vo.ProdukDetailLaboratoriumHasilVO;

@Component
public class ProdukDetailLaboratoriumHasilConverter extends FindConverterDao implements
BaseVoConverter<ProdukDetailLaboratoriumHasilVO, ProdukDetailLaboratoriumHasil>{
	
	public ProdukDetailLaboratoriumHasil transferVOToModel(ProdukDetailLaboratoriumHasilVO vo, ProdukDetailLaboratoriumHasil model) {
		if (null == model)
			model = new ProdukDetailLaboratoriumHasil();

		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, ProdukDetailLaboratoriumHasil.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return model;

	}

	public List<ProdukDetailLaboratoriumHasilVO> transferListOfModelToListOfVO(List<ProdukDetailLaboratoriumHasil> models,
			List<ProdukDetailLaboratoriumHasilVO> vos) {
		if (null == vos)
			vos = new ArrayList<ProdukDetailLaboratoriumHasilVO>();

		if (null == models)
			return vos;

		for (ProdukDetailLaboratoriumHasil model : models) {
			ProdukDetailLaboratoriumHasilVO vo = new ProdukDetailLaboratoriumHasilVO();
			transferModelToVO(model, vo);
			vos.add(vo);
		}

		return vos;
	}
	
	/*public List<ProdukDetailLaboratoriumHasil> transferListOfVOToListOfModel(List<ProdukDetailLaboratoriumHasilVO> vos,
			List<ProdukDetailLaboratoriumHasil> models) {
		if (null == models)
			models = new ArrayList<ProdukDetailLaboratoriumHasil>();

		if (null == vos)
			return models;

		for (ProdukDetailLaboratoriumHasilVO vo : vos) {
			ProdukDetailLaboratoriumHasil model = new ProdukDetailLaboratoriumHasil();
			model = transferVOToModel(vo, model);
			models.add(model);
		}

		return models;
	}*/

	public ProdukDetailLaboratoriumHasilVO transferModelToVO(ProdukDetailLaboratoriumHasil model, ProdukDetailLaboratoriumHasilVO vo) {
		if (null == vo)
			vo = new ProdukDetailLaboratoriumHasilVO();

		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, ProdukDetailLaboratoriumHasilVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vo;
	}
	
}
