package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.PengkajianAwalDao;
import com.jasamedika.medifirst2000.dto.PengkajianAwalDto;
import com.jasamedika.medifirst2000.entities.PengkajianAwal;
import com.jasamedika.medifirst2000.service.PengkajianAwalService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.PengkajianAwalVO;

@Service("PengkajianAwalService")
public class PengkajianAwalServiceImpl implements PengkajianAwalService{

	@Autowired
	private PengkajianAwalDao pengkajianAwalDao;
	
	@Autowired
	private BaseConverterImpl<PengkajianAwalVO, PengkajianAwal> pengkajianAwalConverter;
	
	@Override
	public Map<String, Object> save(PengkajianAwalVO vo){
		Map<String, Object> result = new HashMap<>();
		
		PengkajianAwal pengkajianAwal = new PengkajianAwal();
		
		if(CommonUtil.isNotNullOrEmpty(vo)){
			pengkajianAwal = pengkajianAwalConverter.transferVOToModel(vo, new PengkajianAwal());
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getHeadPengkajianAwal())){
			pengkajianAwalConverter.transferVOToModel(vo.getHeadPengkajianAwal(), new PengkajianAwal());
		}
		if(CommonUtil.isNotNullOrEmpty(pengkajianAwal)){
			PengkajianAwal pengkajianAwalResult =  pengkajianAwalDao.save(pengkajianAwal);
			result.put("id", pengkajianAwalResult);
		}
		
		return result;
	}
	
	@Override
	public PengkajianAwal getHeadPengkajianAwal(Integer id){
		PengkajianAwal result = new PengkajianAwal();
		if(CommonUtil.isNotNullOrEmpty(id)){
			result = pengkajianAwalDao.getPengkajianAwal(id);
		}
		return result;
	}
}
