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.MonitoringMesinAutoClaveBowidickDao;
import com.jasamedika.medifirst2000.dao.PegawaiDao;
import com.jasamedika.medifirst2000.dto.MonitoringMesinAutoClaveBowidickDto;
import com.jasamedika.medifirst2000.entities.Mesin;
import com.jasamedika.medifirst2000.entities.MonitoringMesinAutoClaveBowidick;
import com.jasamedika.medifirst2000.entities.Pegawai;
import com.jasamedika.medifirst2000.service.MonitoringMesinAutoClaveBowidickService;

@Service("MonitoringMesinAutoClaveBowidickService")
public class MonitoringMesinAutoClaveBowidickServiceImpl implements MonitoringMesinAutoClaveBowidickService{
	@Autowired
	private MonitoringMesinAutoClaveBowidickDao monitoringMesinAutoClaveBowidickDao;
	
	@Autowired
	private MesinDao mesinDao;
	
	@Autowired
	private PegawaiDao pegawaiDao;
	
	@Override
	public Map<String, Object> saveMonitoringMesinAutoClaveBowidick(MonitoringMesinAutoClaveBowidickDto dto) {
		Map<String, Object> result = new HashMap<>();
		
		MonitoringMesinAutoClaveBowidick monitoringMesinAutoClaveBowidick = new MonitoringMesinAutoClaveBowidick();
		monitoringMesinAutoClaveBowidick.setNoRec(dto.getNoRec());
		monitoringMesinAutoClaveBowidick.setTanggal(dto.getTanggal());
		monitoringMesinAutoClaveBowidick.setProgram(dto.getProgram());
		monitoringMesinAutoClaveBowidick.setHasil(dto.getHasil());
		monitoringMesinAutoClaveBowidick.setKeterangan(dto.getKeterangan());
		monitoringMesinAutoClaveBowidick.setStatusEnabled(dto.getStatusEnabled());
		Mesin mesin = this.mesinDao.findOne(dto.getMesinId());
		monitoringMesinAutoClaveBowidick.setMesin(mesin);
		Pegawai operator = this.pegawaiDao.findById(dto.getOperatorId());
		monitoringMesinAutoClaveBowidick.setOperator(operator);
		MonitoringMesinAutoClaveBowidick monitoringMesinAutoClaveBowidickResult = this.monitoringMesinAutoClaveBowidickDao.save(monitoringMesinAutoClaveBowidick);
		if(monitoringMesinAutoClaveBowidickResult.getNoRec() != null){
			result.put("data", monitoringMesinAutoClaveBowidickResult.getNoRec());
		}
		return result;
	}

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

}
