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.PMDiagnosis;
import com.jasamedika.medifirst2000.vo.PMDiagnosisVO;

/**
 * @author Shakato
 *
 */
@Component
public class PMDiagnosisConverter extends FindConverterDao implements BaseVoConverter<PMDiagnosisVO, PMDiagnosis>{

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

	@Override
	public List<PMDiagnosisVO> transferListOfModelToListOfVO(List<PMDiagnosis> models,
			List<PMDiagnosisVO> vos) {
			if (vos == null) {
				vos = new ArrayList<PMDiagnosisVO>();
			}
			
			if (models == null) {
				return vos;
			}
			
			for (PMDiagnosis status : models) {
				PMDiagnosisVO vo = new PMDiagnosisVO();
				vo=transferModelToVO(status, vo);
				vos.add(vo);
			}
			return vos;
	}

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

		return vo;
	}

	

}
