package ru.micord.ervu.account_applications.service;

import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import ru.micord.ervu.account_applications.dao.UserApplicationListDao;

/**
 * @author gulnaz
 */
@Service
@DependsOn("liquibase")
public class ApplicationStatusUpdateSchedulerService {

  private final UserApplicationListDao applicationListDao;

  @Value("${scheduler.status_update.app_age.minutes:5}")
  private long minutes;

  public ApplicationStatusUpdateSchedulerService(UserApplicationListDao applicationListDao) {
    this.applicationListDao = applicationListDao;
  }

  @Scheduled(cron = "${scheduler.status_update.cron:0 */5 * * * *}")
  @SchedulerLock(name = "updateApplicationStatus")
  public void update() {
    applicationListDao.saveAgreedStatusForSentAppsOlderThan(minutes);
  }
}
