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.AlatTerpasangDetail;
import com.jasamedika.medifirst2000.vo.AlatTerpasangDetailVO;

@Component
public class AlatTerpasangDetailConverter implements BaseVoConverter<AlatTerpasangDetailVO, AlatTerpasangDetail> {


	@Override
	public AlatTerpasangDetail transferVOToModel(AlatTerpasangDetailVO vo, AlatTerpasangDetail model) {
		if (null == model)
			model = new AlatTerpasangDetail();

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

		return model;
	}

	@Override
	public List<AlatTerpasangDetailVO> transferListOfModelToListOfVO(List<AlatTerpasangDetail> models, List<AlatTerpasangDetailVO> vos) {

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

		if (null == models)
			return vos;

		for (AlatTerpasangDetail alatTerpasangDetail : models) {
			AlatTerpasangDetailVO vo = new AlatTerpasangDetailVO();
			vo=transferModelToVO(alatTerpasangDetail, vo);
			vos.add(vo);
		}

		return vos;
	}

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

		return vo;
	}
	
	
	
	

}
