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.ProgramDanPerencanaanPenanganan;
import com.jasamedika.medifirst2000.vo.ProgramDanPerencanaanPenangananVO;

@Component
public class ProgramDanPerencanaanPenangananConverter implements BaseVoConverter<ProgramDanPerencanaanPenangananVO, ProgramDanPerencanaanPenanganan>{

	@Override
	public ProgramDanPerencanaanPenanganan transferVOToModel(ProgramDanPerencanaanPenangananVO vo,
			ProgramDanPerencanaanPenanganan model) {
		if (null == model)
			model = new ProgramDanPerencanaanPenanganan();

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

		return model;
	}

	@Override
	public List<ProgramDanPerencanaanPenangananVO> transferListOfModelToListOfVO(
			List<ProgramDanPerencanaanPenanganan> models, List<ProgramDanPerencanaanPenangananVO> vos) {
		if (null == vos)
			vos = new ArrayList<ProgramDanPerencanaanPenangananVO>();

		if (null == models)
			return vos;

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

		return vos;
	}

	@Override
	public ProgramDanPerencanaanPenangananVO transferModelToVO(ProgramDanPerencanaanPenanganan model,
			ProgramDanPerencanaanPenangananVO vo) {
		if (null == vo)
			vo = new ProgramDanPerencanaanPenangananVO();

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

}
