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.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;

import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.ResikoJatuhDetailDao;
import com.jasamedika.medifirst2000.entities.PeralatanDetail;
import com.jasamedika.medifirst2000.entities.ResikoJatuh;
import com.jasamedika.medifirst2000.entities.ResikoJatuhDetail;
import com.jasamedika.medifirst2000.entities.TransferPasienExsternal;
import com.jasamedika.medifirst2000.entities.TransferPasienInternal;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.PasienDaftarService;
import com.jasamedika.medifirst2000.service.ResikoJatuhDetailService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.ResikoJatuhDetailCustomVO;
import com.jasamedika.medifirst2000.vo.ResikoJatuhDetailVO;
import com.jasamedika.medifirst2000.vo.ResikoJatuhVO;
import com.jasamedika.medifirst2000.vo.TransferPasienExsternalVO;
import com.jasamedika.medifirst2000.vo.TransferPasienInternalVO;

@Service("resikoJatuhDetailService")
public class ResikoJatuhDetailServiceImpl implements ResikoJatuhDetailService{
	
	@Autowired
	private BaseConverterImpl<ResikoJatuhVO, ResikoJatuh> resikoJatuhConverter;
	
	@Autowired
	private BaseConverterImpl<TransferPasienInternalVO, TransferPasienInternal> transferPasienInternalConverter;
	
	@Autowired
	private BaseConverterImpl<TransferPasienExsternalVO, TransferPasienExsternal> transferPasienExsternalConverter;
		
	@Autowired
	private PasienDaftarService pasienDaftarService;
	
	@Autowired
	private BaseConverterImpl<ResikoJatuhDetailVO, ResikoJatuhDetail> resikoJatuhDetailConverter;
	
	@Autowired
	private ResikoJatuhDetailDao resikoJatuhDetailDao;

	@Override
	public ResikoJatuhDetailCustomVO add(ResikoJatuhDetailCustomVO vo) throws JpaSystemException, ServiceVOException {
		return null;
	}

	@Override
	public ResikoJatuhDetailCustomVO update(ResikoJatuhDetailCustomVO vo)
			throws JpaSystemException, ServiceVOException {
		return null;
	}

	@Override
	public Boolean delete(String key) throws JpaSystemException {
		return null;
	}

	@Override
	public ResikoJatuhDetailCustomVO findById(String key) throws JpaSystemException {
		return null;
	}

	@Override
	public List<ResikoJatuhDetailCustomVO> findAll() throws JpaSystemException {
		return null;
	}

	@Override
	public Map<String, Object> findAllWithPageAndLimitAndSortByAndDirectionParameter(Integer page, Integer limit,
			String sort, String dir) {
		return null;
	}

	@Override
	public Map<String, Object> addResikoJatuh(ResikoJatuhDetailCustomVO vo) {
		ArrayList<String> resultStringArray = new ArrayList<String>();
		for(ResikoJatuhDetailVO vos : vo.getResikoJatuhDetail())
		{
			resultStringArray.add(vos.getResikoJatuh().getId().toString());
			ResikoJatuhDetail resikoJatuhDetail = resikoJatuhDetailConverter.transferVOToModel(vos, new ResikoJatuhDetail());
			if(CommonUtil.isNotNullOrEmpty(vos.getResikoJatuh())){
				resikoJatuhDetail.setResikoJatuh(resikoJatuhConverter.transferVOToModel(vos.getResikoJatuh(), new ResikoJatuh()));
			}
			resikoJatuhDetail.setIsNilai(resikoJatuhDetail.getIsNilai());
			if(CommonUtil.isNotNullOrEmpty(vo.getTransferPasienInternal())){
				resikoJatuhDetail.setTransferPasienInternal(transferPasienInternalConverter.transferVOToModel(vo.getTransferPasienInternal(), new TransferPasienInternal()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getTransferPasienExsternal())){
				resikoJatuhDetail.setTransferPasienExsternal(transferPasienExsternalConverter.transferVOToModel(vo.getTransferPasienExsternal(), new TransferPasienExsternal()));
			}
			ResikoJatuhDetail resultModel = resikoJatuhDetailDao.save(resikoJatuhDetail);		
			
		}
		Map<String,Object>result=new HashMap<String,Object>();
		result.put("result", resultStringArray);
		return result;
	}

	@Override
	public Map<String, Object> updateResikoJatuh(ResikoJatuhDetailCustomVO vo) {
		return null;
	}

}
