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.AlatDao;
import com.jasamedika.medifirst2000.dao.MonitoringAlatSterilDao;
import com.jasamedika.medifirst2000.dao.PegawaiDao;
import com.jasamedika.medifirst2000.dao.RuanganDao;
import com.jasamedika.medifirst2000.dao.SatuanStandarDao;
import com.jasamedika.medifirst2000.dto.MonitoringAlatSterilDto;
import com.jasamedika.medifirst2000.entities.Alat;
import com.jasamedika.medifirst2000.entities.Monitoring;
import com.jasamedika.medifirst2000.entities.MonitoringAlatSteril;
import com.jasamedika.medifirst2000.entities.Pegawai;
import com.jasamedika.medifirst2000.entities.Ruangan;
import com.jasamedika.medifirst2000.entities.SatuanStandar;
import com.jasamedika.medifirst2000.service.MonitoringAlatSterilService;

@Service("MonitoringAlatSterilService")
public class MonitoringAlatSterilServiceImpl implements MonitoringAlatSterilService {
	@Autowired
	private MonitoringAlatSterilDao monitoringAlatSterilDao;
	
	@Autowired
	private RuanganDao ruanganDao;
	
	@Autowired
	private PegawaiDao pegawaiDao;
	
	@Autowired
	private AlatDao alatDao;
	
	@Autowired
	private SatuanStandarDao satuanStandarDao;

	@Override
	public Map<String, Object> saveMonitoringAlatSterilService(MonitoringAlatSterilDto dto) {
		Map<String, Object> result = new HashMap<>();
		MonitoringAlatSteril monitoringAlatSteril = new MonitoringAlatSteril();
		monitoringAlatSteril.setNoRec(dto.getNoRec());
		monitoringAlatSteril.setTanggalPengecekan(dto.getTanggalPengecekan());
		Ruangan ruangan = this.ruanganDao.findById(dto.getRuanganId());
		monitoringAlatSteril.setRuangan(ruangan);
		Alat alat = this.alatDao.findOne(dto.getAlatId());
		monitoringAlatSteril.setAlat(alat);
		Pegawai petugas = this.pegawaiDao.findById(dto.getPetugasId());
		monitoringAlatSteril.setPetugas(petugas);
		SatuanStandar satuanStandar = this.satuanStandarDao.findById(dto.getSatuanId());
		monitoringAlatSteril.setSatuan(satuanStandar);
		monitoringAlatSteril.setJumlah(dto.getJumlah());
		monitoringAlatSteril.setTanggalKadaluarsa(dto.getTanggalKadaluarsa());
		monitoringAlatSteril.setTanggalSteril(dto.getTanggalSteril());
		monitoringAlatSteril.setStatusEnabled(dto.getStatusEnabled());
		MonitoringAlatSteril monitoringAlatSterilResult = this.monitoringAlatSterilDao.save(monitoringAlatSteril);
		if(monitoringAlatSterilResult.getNoRec() != null) {
			result.put("data", monitoringAlatSterilResult.getNoRec());
		}
		return result;
	}

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

}
