# frozen_string_literal: true

module RedmineUxToolkit
  module Patches
    module ApplicationControllerPatch
      def self.prepended(base)
        base.before_action :ux_toolkit_check_cron_monitor
      end

      private

      def ux_toolkit_check_cron_monitor
        return unless request.get?
        return unless request.format.html?

        RedmineUxToolkit::Services::CronMonitor.check_from_web_request(
          server_admin_email: RedmineUxToolkit::Services::CronMonitor.server_admin_email(request.env)
        )
      end
    end
  end
end
