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.google.gson.GsonBuilder;
import com.jasamedika.medifirst2000.converter.base.BaseVoConverter;
import com.jasamedika.medifirst2000.entities.SatuanStandar;
import com.jasamedika.medifirst2000.vo.SatuanStandarVO;

/**
 * Converter class between Pasien and PasienVO
 * 
 * @author Askur
 */
@Component
public class SatuanStandarConverter implements BaseVoConverter<SatuanStandarVO, SatuanStandar> {

	@Override
	public SatuanStandar transferVOToModel(SatuanStandarVO vo, SatuanStandar model) {
		if (null == model)
			model = new SatuanStandar();

		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = vo.serialize(fieldsToInclude, vo.getClass().getName());
			Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
			String json = gson.toJson(serialized);
			model = gson.fromJson(json, SatuanStandar.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return model;
	}

	@Override
	public List<SatuanStandarVO> transferListOfModelToListOfVO(List<SatuanStandar> models, List<SatuanStandarVO> vos) {

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

		if (null == models)
			return vos;

		for (SatuanStandar satuan : models) {
			SatuanStandarVO vo = new SatuanStandarVO();
			vo = transferModelToVO(satuan, vo);
			vos.add(vo);
		}

		return vos;
	}

	@Override
	public SatuanStandarVO transferModelToVO(SatuanStandar model, SatuanStandarVO vo) {
		if (null == vo)
			vo = new SatuanStandarVO();
		try {
			String[] fieldsToInclude = null;
			Map<String, Object> serialized = model.serialize(fieldsToInclude, model.getClass().getSimpleName());
			Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
			String json = gson.toJson(serialized);
			vo = gson.fromJson(json, SatuanStandarVO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return vo;
	}

}
