package de.ivu.elect.business.security.control;

import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.ejb.DependsOn;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.ivu.elect.business.system.boundary.SystemLogWriter;
import de.ivu.elect.business.system.entity.SystemLogQuelle;
import de.ivu.elect.jee.cron.AbstractSingleCronTimer;

// Nicht als Vorlage nehmen
@Startup
@Singleton
@DependsOn("StartupSingleton")
public class NlAirGapCheckCronTimer extends AbstractSingleCronTimer {

  @Inject
  private transient NlAirGapCheck nlAirGapCheck;

  @Inject
  private transient SystemLogWriter systemLogWriter;

  private static final Logger LOG = LoggerFactory.getLogger(NlAirGapCheckCronTimer.class);

  @PostConstruct
  public void init() {
    LOG.info("Init " + getJobName());
    try {
      createTimer();
      LOG.info("Init " + getJobName() + " - done");
    } catch (Exception e) {
      systemLogWriter.writeErrorLogMessageFuerSystemMandant(e.getMessage(), e, SystemLogQuelle.SYSTEM);
    }
  }

  @Nullable
  @Override
  protected String getCrontab() {
    return "0,5,10,15,20,25,30,35,40,45,50,55 * * * *";
  }

  @Override
  protected void timeout() {
    nlAirGapCheck.doIt();
  }

  @Override
  public String getJobName() {
    return "NlAirGapCheck";
  }
}
