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.PencatatanSuhuMesinDao;
import com.jasamedika.medifirst2000.entities.Mesin;
import com.jasamedika.medifirst2000.entities.Pegawai;
import com.jasamedika.medifirst2000.entities.PencatatanSuhuMesin;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.PencatatanSuhuMesinService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.MesinVO;
import com.jasamedika.medifirst2000.vo.PegawaiVO;
import com.jasamedika.medifirst2000.vo.PencatatanSuhuMesinVO;

@Service("PencatatanSuhuMesinService")
public class PencatatanSuhuMesinServiceImpl extends BaseVoServiceImpl implements PencatatanSuhuMesinService<PencatatanSuhuMesinVO> {

	@Autowired
	private PencatatanSuhuMesinDao pencatatanSuhuMesinDao;
	
	@Autowired
	private BaseConverterImpl<PencatatanSuhuMesinVO,PencatatanSuhuMesin> realisasiTargetConverter;
	
	@Autowired
	private BaseConverterImpl<PegawaiVO,Pegawai> pegawaiConverter;
	
	@Autowired
	private BaseConverterImpl<MesinVO,Mesin> mesinConverter;
	
	@Override
	public Map<String,Object> addPencatatanSuhuMesin(PencatatanSuhuMesinVO vo) {

		PencatatanSuhuMesin pencatatanSuhuMesin=new PencatatanSuhuMesin();
				
		if(CommonUtil.isNotNullOrEmpty(vo)){
			pencatatanSuhuMesin=realisasiTargetConverter.transferVOToModel(vo, new PencatatanSuhuMesin());
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getMesin())){
			pencatatanSuhuMesin.setMesin(mesinConverter.transferVOToModel(vo.getMesin(), new Mesin()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getPetugas())){
			pencatatanSuhuMesin.setPetugas(pegawaiConverter.transferVOToModel(vo.getPetugas(), new Pegawai()));
		}
		
		pencatatanSuhuMesin.setKeterangan("Pencatatan");
		
		PencatatanSuhuMesin pencatatanSuhuMesinResult=pencatatanSuhuMesinDao.save(pencatatanSuhuMesin);
		
		Map<String,Object> result=new HashMap<String,Object>();
		
		if (CommonUtil.isNotNullOrEmpty(pencatatanSuhuMesin)) {
			result.put("noRec", pencatatanSuhuMesinResult.getNoRec());
		}
		
		return result;
		
	}
	
	@Override
	public Map<String,Object> updatePencatatanSuhuMesin(PencatatanSuhuMesinVO vo) {

		PencatatanSuhuMesin pencatatanSuhuMesin=new PencatatanSuhuMesin();
				
		if(CommonUtil.isNotNullOrEmpty(vo)){
			pencatatanSuhuMesin=realisasiTargetConverter.transferVOToModel(vo, new PencatatanSuhuMesin());
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getMesin())){
			pencatatanSuhuMesin.setMesin(mesinConverter.transferVOToModel(vo.getMesin(), new Mesin()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getPetugas())){
			pencatatanSuhuMesin.setPetugas(pegawaiConverter.transferVOToModel(vo.getPetugas(), new Pegawai()));
		}
		
		PencatatanSuhuMesin pencatatanSuhuMesinResult=pencatatanSuhuMesinDao.save(pencatatanSuhuMesin);
		
		Map<String,Object> result=new HashMap<String,Object>();
		
		if (CommonUtil.isNotNullOrEmpty(pencatatanSuhuMesin)) {
			result.put("noRec", pencatatanSuhuMesinResult.getNoRec());
		}
		
		return result;
		
	}
	
	@Override
	public Map<String,Object> findAllPencatatanSuhuMesin() {
		Map<String,Object> result=new HashMap<String,Object>();
		List<PencatatanSuhuMesin> resultModel=(List<PencatatanSuhuMesin>) pencatatanSuhuMesinDao.findAll();
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("pencatatanSuhuMesin", resultModel);
			result.put("dataFound", true);
		}else{
			result.put("dataFound", false);
		}
		return result;
	}
	
	

	@Override
	public Map<String, Object> getMesin() {
		Map<String, Object> result = new HashMap<>();
		result.put("data", this.pencatatanSuhuMesinDao.getMesin());
		return result;
	}
	
	

	@Override
	public Map<String, Object> getPencatatanSuhuMesin() {
		Map<String, Object> result = new HashMap<>();
		result.put("data", this.pencatatanSuhuMesinDao.getPencatatanSuhuMesin());
		return result;
	}
	
	@Override
	public Map<String, Object> savePencatatanSuhuMesinGrafik(PencatatanSuhuMesinVO vo) {
		PencatatanSuhuMesin pencatatanSuhuMesin=new PencatatanSuhuMesin();
		
		if(CommonUtil.isNotNullOrEmpty(vo)){
			pencatatanSuhuMesin=realisasiTargetConverter.transferVOToModel(vo, new PencatatanSuhuMesin());
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getMesin())){
			pencatatanSuhuMesin.setMesin(mesinConverter.transferVOToModel(vo.getMesin(), new Mesin()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getPetugas())){
			pencatatanSuhuMesin.setPetugas(pegawaiConverter.transferVOToModel(vo.getPetugas(), new Pegawai()));
		}
		
		pencatatanSuhuMesin.setKeterangan("Grafik");
		
		PencatatanSuhuMesin pencatatanSuhuMesinResult=pencatatanSuhuMesinDao.save(pencatatanSuhuMesin);
		
		Map<String,Object> result=new HashMap<String,Object>();
		
		if (CommonUtil.isNotNullOrEmpty(pencatatanSuhuMesin)) {
			result.put("noRec", pencatatanSuhuMesinResult.getNoRec());
		}
		
		return result;
	}
	
	

	@Override
	public Map<String, Object> getPencatatanSuhuMesinGrafik() {
		Map<String, Object> result = new HashMap<>();
		result.put("data", this.pencatatanSuhuMesinDao.getPencatatanSuhuMesinGrafik());
		return result;
	}

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

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

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

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

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

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


}
