package com.jasamedika.medifirst2000.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jasamedika.medifirst2000.dao.MesinDao;
import com.jasamedika.medifirst2000.dao.MonitoringTestMesinAutoclaveDao;
import com.jasamedika.medifirst2000.dao.PegawaiDao;
import com.jasamedika.medifirst2000.dto.MonitoringTestMesinAutoclaveDto;
import com.jasamedika.medifirst2000.entities.Mesin;
import com.jasamedika.medifirst2000.entities.MonitoringTestMesinAutoclave;
import com.jasamedika.medifirst2000.entities.Pegawai;
import com.jasamedika.medifirst2000.service.MonitoringTestmesinAutoClaveService;

@Service("MonitoringTestmesinAutoClaveService")
public class MonitoringTestmesinAutoClaveServiceImpl implements MonitoringTestmesinAutoClaveService {
	@Autowired
	private MonitoringTestMesinAutoclaveDao monitoringTestMesinAutoclaveDao;
	
	@Autowired
	private MesinDao mesinDao;
	
	@Autowired
	private PegawaiDao pegawaiDao;
	
	@Override
	public Map<String, Object> saveMonitoringTestMesinAutoClave(MonitoringTestMesinAutoclaveDto dto) {
		Map<String, Object> result = new HashMap<>();
		MonitoringTestMesinAutoclave monitoringTestMesinAutoclave = new MonitoringTestMesinAutoclave();
		monitoringTestMesinAutoclave.setNoRec(dto.getNoRec());
		monitoringTestMesinAutoclave.setTanggal(dto.getTanggal());
		monitoringTestMesinAutoclave.setJamMasuk(dto.getJamMasuk());
		monitoringTestMesinAutoclave.setJamKeluar(dto.getJamKeluar());
		monitoringTestMesinAutoclave.setPemeriksaan(dto.getPemeriksaan());
		monitoringTestMesinAutoclave.setKeterangan(dto.getKeterangan());
		monitoringTestMesinAutoclave.setSuhu(dto.getSuhu());
		monitoringTestMesinAutoclave.setStatusEnabled(dto.getStatusEnabled());
		Mesin mesin = this.mesinDao.findOne(dto.getMesinId());
		monitoringTestMesinAutoclave.setMesin(mesin);
		Pegawai petugas = this.pegawaiDao.findById(dto.getPetugasId());
		monitoringTestMesinAutoclave.setPetugas(petugas);
		MonitoringTestMesinAutoclave monitoringTestMesinAutoclaveResult = this.monitoringTestMesinAutoclaveDao.save(monitoringTestMesinAutoclave);
		
		if(monitoringTestMesinAutoclaveResult.getNoRec() != null) {
			result.put("data", monitoringTestMesinAutoclaveResult.getNoRec());
		}
		
		return result;
	}

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

}
