package com.jasamedika.medifirst2000.service.impl;

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.MappingBmhpToSetAlatDao;
import com.jasamedika.medifirst2000.entities.Alat;
import com.jasamedika.medifirst2000.entities.BundleSetAlat;
import com.jasamedika.medifirst2000.entities.MappingBmhpToSetAlat;
import com.jasamedika.medifirst2000.entities.Produk;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.MappingBmhpToSetAlatService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.AlatVO;
import com.jasamedika.medifirst2000.vo.BundleSetAlatVO;
import com.jasamedika.medifirst2000.vo.MappingBmhpToSetAlatVO;
import com.jasamedika.medifirst2000.vo.ProdukVO;

@Service("MappingBmhpToSetAlatService")
public class MappingBmhpToSetAlatServiceImpl extends BaseVoServiceImpl implements MappingBmhpToSetAlatService<MappingBmhpToSetAlatVO> {

	@Autowired
	private MappingBmhpToSetAlatDao mappingBmhpToSetAlatDao;
	
	@Autowired
	private BaseConverterImpl<MappingBmhpToSetAlatVO, MappingBmhpToSetAlat> mappingBmhpToSetAlatConverter;
	
	@Autowired
	private BaseConverterImpl<AlatVO, Alat> alatConverter;
	
	@Autowired
	private BaseConverterImpl<BundleSetAlatVO, BundleSetAlat> bundleSetAlatConverter;
	
	@Override
	public Map<String, Object> addMappingBmhpToSetAlats(List<MappingBmhpToSetAlatVO> vos) {
		Map<String, Object> result = new HashMap<String,Object>();
		for(MappingBmhpToSetAlatVO vo : vos){
			MappingBmhpToSetAlat mappingBmhpToSetAlat = new MappingBmhpToSetAlat();
			if(CommonUtil.isNotNullOrEmpty(vo)){
				mappingBmhpToSetAlat = mappingBmhpToSetAlatConverter.transferVOToModel(vo, new MappingBmhpToSetAlat());
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getBmhp())){
				mappingBmhpToSetAlat.setBmhp(alatConverter.transferVOToModel(vo.getBmhp(), new Alat()));
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getBundleSetAlat())){
				mappingBmhpToSetAlat.setBundleSetAlat(bundleSetAlatConverter.transferVOToModel(vo.getBundleSetAlat(), new BundleSetAlat()));
			}
			
			MappingBmhpToSetAlat resultModel = mappingBmhpToSetAlatDao.save(mappingBmhpToSetAlat);
			
			if(CommonUtil.isNotNullOrEmpty(resultModel)){
				result.put("id", resultModel.getId());
			}
			
		}

		
		return result;
	}
	
	@Override
	public Map<String, Object> updateMappingBmhpToSetAlats(List<MappingBmhpToSetAlatVO> vos) {
		Map<String, Object> result = new HashMap<String,Object>();
		for(MappingBmhpToSetAlatVO vo : vos){
			MappingBmhpToSetAlat mappingBmhpToSetAlat = new MappingBmhpToSetAlat();
			if(CommonUtil.isNotNullOrEmpty(vo)){
				mappingBmhpToSetAlat = mappingBmhpToSetAlatConverter.transferVOToModel(vo, new MappingBmhpToSetAlat());
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getBmhp())){
				mappingBmhpToSetAlat.setBmhp(alatConverter.transferVOToModel(vo.getBmhp(), new Alat()));
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getBundleSetAlat())){
				mappingBmhpToSetAlat.setBundleSetAlat(bundleSetAlatConverter.transferVOToModel(vo.getBundleSetAlat(), new BundleSetAlat()));
			}
			
			MappingBmhpToSetAlat resultModel = mappingBmhpToSetAlatDao.save(mappingBmhpToSetAlat);
			
			if(CommonUtil.isNotNullOrEmpty(resultModel)){
				result.put("id", resultModel.getId());
			}
			
		}

		return result;
	}
	
	@Override
	public Map<String, Object> addMappingBmhpToSetAlat(MappingBmhpToSetAlatVO vo) {
		Map<String, Object> result = new HashMap<String,Object>();
		
			MappingBmhpToSetAlat mappingBmhpToSetAlat = new MappingBmhpToSetAlat();
			if(CommonUtil.isNotNullOrEmpty(vo)){
				mappingBmhpToSetAlat = mappingBmhpToSetAlatConverter.transferVOToModel(vo, new MappingBmhpToSetAlat());
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getBmhp())){
				mappingBmhpToSetAlat.setBmhp(alatConverter.transferVOToModel(vo.getBmhp(), new Alat()));
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getBundleSetAlat())){
				mappingBmhpToSetAlat.setBundleSetAlat(bundleSetAlatConverter.transferVOToModel(vo.getBundleSetAlat(), new BundleSetAlat()));
			}
			
			MappingBmhpToSetAlat resultModel = mappingBmhpToSetAlatDao.save(mappingBmhpToSetAlat);
			
			if(CommonUtil.isNotNullOrEmpty(resultModel)){
				result.put("id", resultModel.getId());
			}
			
		return result;
	}
	
	@Override
	public Map<String, Object> updateMappingBmhpToSetAlat(MappingBmhpToSetAlatVO vo) {
		Map<String, Object> result = new HashMap<String,Object>();
		
			MappingBmhpToSetAlat mappingBmhpToSetAlat = new MappingBmhpToSetAlat();
			if(CommonUtil.isNotNullOrEmpty(vo)){
				mappingBmhpToSetAlat = mappingBmhpToSetAlatConverter.transferVOToModel(vo, new MappingBmhpToSetAlat());
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getBmhp())){
				mappingBmhpToSetAlat.setBmhp(alatConverter.transferVOToModel(vo.getBmhp(), new Alat()));
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getBundleSetAlat())){
				mappingBmhpToSetAlat.setBundleSetAlat(bundleSetAlatConverter.transferVOToModel(vo.getBundleSetAlat(), new BundleSetAlat()));
			}
			
			MappingBmhpToSetAlat resultModel = mappingBmhpToSetAlatDao.save(mappingBmhpToSetAlat);
			
			if(CommonUtil.isNotNullOrEmpty(resultModel)){
				result.put("id", resultModel.getId());
			}
		
		return result;
	}
	

	
	@Override
	public Map<String,Object> findAllMappingBmhpToSetAlat() {
		Map<String,Object> result=new HashMap<String,Object>();
		List<MappingBmhpToSetAlat> resultModel=(List<MappingBmhpToSetAlat>) mappingBmhpToSetAlatDao.findAll();
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("MappingBmhpToSetAlat", resultModel);
			result.put("dataFound", true);
		}else{
			result.put("dataFound", false);
		}
		return result;
	}
	
	

	@Override
	public Map<String, Object> getMappingBmhhpToSetAlatByBundle(Integer idBundle) {
		Map<String, Object> result = new HashMap<>();
		result.put("data", this.mappingBmhpToSetAlatDao.getAlatByBundle(idBundle));
		return result;
	}

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

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

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

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

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

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

}
