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.JenisLimbahB3MasukDao;
import com.jasamedika.medifirst2000.entities.JenisLimbahB3Masuk;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.JenisLimbahB3MasukService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.StringUtil;
import com.jasamedika.medifirst2000.vo.JenisLimbahB3MasukVO;

@Service("JenisLimbahB3MasukService")
public class JenisLimbahB3MasukServiceImpl extends BaseVoServiceImpl implements JenisLimbahB3MasukService<JenisLimbahB3MasukVO> {



	@Autowired
	private JenisLimbahB3MasukDao jenisLimbahB3MasukDao;

	@Autowired
	private BaseConverterImpl<JenisLimbahB3MasukVO, JenisLimbahB3Masuk> jenisLimbahB3MasukConverter;
	
	@Override
	public Map<String,Object> addJenisLimbahB3(JenisLimbahB3MasukVO vo) {
		
		JenisLimbahB3Masuk jenisLimbahB3Masuk=new JenisLimbahB3Masuk();		
		if(CommonUtil.isNotNullOrEmpty(vo)){
			jenisLimbahB3Masuk = jenisLimbahB3MasukConverter.transferVOToModel(vo, new JenisLimbahB3Masuk());
		}
		
		jenisLimbahB3Masuk.setKdJenisLimbah(StringUtil.formatNumber(String.valueOf(jenisLimbahB3MasukDao.getCount()+1), 3));
		JenisLimbahB3Masuk jenisLimbahB3MasukResult=jenisLimbahB3MasukDao.save(jenisLimbahB3Masuk);
		Map<String,Object> result=new HashMap<String,Object>();
		if (CommonUtil.isNotNullOrEmpty(jenisLimbahB3MasukResult)) {
			result.put("id", jenisLimbahB3MasukResult.getId());
		}
		
		return result;
		
	}
	
	@Override
	public Map<String,Object> updateJenisLimbahB3(JenisLimbahB3MasukVO vo) {
		
		JenisLimbahB3Masuk jenisLimbahB3Masuk=new JenisLimbahB3Masuk();		
		if(CommonUtil.isNotNullOrEmpty(vo)){
			jenisLimbahB3Masuk = jenisLimbahB3MasukConverter.transferVOToModel(vo, new JenisLimbahB3Masuk());
		}
		
		jenisLimbahB3Masuk.setKdJenisLimbah(StringUtil.formatNumber(String.valueOf(jenisLimbahB3MasukDao.getCount()+1), 3));
		JenisLimbahB3Masuk jenisLimbahB3MasukResult=jenisLimbahB3MasukDao.save(jenisLimbahB3Masuk);
		Map<String,Object> result=new HashMap<String,Object>();
		if (CommonUtil.isNotNullOrEmpty(jenisLimbahB3MasukResult)) {
			result.put("id", jenisLimbahB3MasukResult.getId());
		}
		
		return result;
		
	}
	
	@Override
	public boolean deleteJenisLimbahB3(Integer id) {
		if (CommonUtil.isNotNullOrEmpty(id)){
			JenisLimbahB3Masuk jenisLimbahB3Masuk = jenisLimbahB3MasukDao.findOne(id);
			jenisLimbahB3MasukDao.delete(jenisLimbahB3Masuk);
			return true;
		}else{
			return false;
		}
	}
	
	@Override
	public Map<String,Object> findAllAlat() {
		Map<String,Object> result=new HashMap<String,Object>();
		List<JenisLimbahB3Masuk> resultModel=(List<JenisLimbahB3Masuk>) jenisLimbahB3MasukDao.findAll();
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("jenisLimbahB3Masuk", resultModel);
			result.put("dataFound", true);
		}else{
			result.put("dataFound", false);
		}
		return result;
	}

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

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

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

	@Override
	public JenisLimbahB3MasukVO findById(Integer key) throws JpaSystemException {
		return null;
	}

	@Override
	public List<JenisLimbahB3MasukVO> 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> getJenisLimbahB3Masuk(String kategori) {
		Map<String,Object> result=new HashMap<String,Object>();
		result.put("jenisLimbahB3Masuk", jenisLimbahB3MasukDao.getJenisLimbahB3Masuk(kategori));
		return result;
	}
	


}
