<commit_before>class Notifiers::EmailNotificationService
  attr_reader :email_notifications

  def self.run
    log_this("started") unless Rails.env.test?

    new.run

    log_this("completed") unless Rails.env.test?
  end

  def initialize
    @email_notifications = AwardYear.current.settings.email_notifications.current.to_a
    @email_notifications += AwardYear.closed.settings.email_notifications.current.to_a
  end

  def run
    email_notifications.each do |notification|
      public_send(notification.kind, notification.settings.award_year)

      notification.update_column(:sent, true)
    end
  end

  def ep_reminder_support_letters(award_year)
    award_year.form_answers.promotion.includes(:support_letters).each do |form_answer|
      if form_answer.support_letters.count < 2
        Users::PromotionLettersOfSupportReminderMailer.notify(form_answer.id).deliver_later!
      end
    end
  end

  def reminder_to_submit(award_year)
    award_year.form_answers.business.where(submitted: false).each do |form_answer|
      Users::ReminderToSubmitMailer.notify(form_answer.id).deliver_later!
    end
  end

  def shortlisted_notifier(award_year)
    award_year.form_answers.business.shortlisted.each do |form_answer|
      Users::NotifyShortlistedMailer.notify(form_answer.id).deliver_later!
    end
  end

  def not_shortlisted_notifier(award_year)
    award_year.form_answers.not_shortlisted.each do |form_answer|
      if form_answer.promotion?
        Users::NotifyNonShortlistedMailer.ep_notify(form_answer.id).deliver_later!
      else
        Users::NotifyNonShortlistedMailer.notify(form_answer.id).deliver_later!
      end
    end
  end

  def shortlisted_audit_certificate_reminder(award_year)
    award_year.form_answers.shortlisted.each do |form_answer|
      if !form_answer.audit_certificate
        Notifiers::Shortlist::AuditCertificateRequest.new(form_answer).run
      end
    end
  end

  def unsuccessful_notification(award_year)
    # initialy shortlisted but then did not win
    award_year.form_answers.business.unsuccessful.each do |form_answer|
      if form_answer.audit_certificate
        Users::ShortlistedUnsuccessfulFeedbackMailer.notify(form_answer.id).deliver_later!
      end
    end
  end

  def all_unsuccessful_feedback(award_year)
    award_year.form_answers.unsuccessful.each do |form_answer|<commit_msg>[AuditCertificateRequest] should be sent for business applications only<commit_after>class Notifiers::EmailNotificationService
  attr_reader :email_notifications

  def self.run
    log_this("started") unless Rails.env.test?

    new.run

    log_this("completed") unless Rails.env.test?
  end

  def initialize
    @email_notifications = AwardYear.current.settings.email_notifications.current.to_a
    @email_notifications += AwardYear.closed.settings.email_notifications.current.to_a
  end

  def run
    email_notifications.each do |notification|
      public_send(notification.kind, notification.settings.award_year)

      notification.update_column(:sent, true)
    end
  end

  def ep_reminder_support_letters(award_year)
    award_year.form_answers.promotion.includes(:support_letters).each do |form_answer|
      if form_answer.support_letters.count < 2
        Users::PromotionLettersOfSupportReminderMailer.notify(form_answer.id).deliver_later!
      end
    end
  end

  def reminder_to_submit(award_year)
    award_year.form_answers.business.where(submitted: false).each do |form_answer|
      Users::ReminderToSubmitMailer.notify(form_answer.id).deliver_later!
    end
  end

  def shortlisted_notifier(award_year)
    award_year.form_answers.business.shortlisted.each do |form_answer|
      Users::NotifyShortlistedMailer.notify(form_answer.id).deliver_later!
    end
  end

  def not_shortlisted_notifier(award_year)
    award_year.form_answers.not_shortlisted.each do |form_answer|
      if form_answer.promotion?
        Users::NotifyNonShortlistedMailer.ep_notify(form_answer.id).deliver_later!
      else
        Users::NotifyNonShortlistedMailer.notify(form_answer.id).deliver_later!
      end
    end
  end

  def shortlisted_audit_certificate_reminder(award_year)
    award_year.form_answers.business.shortlisted.each do |form_answer|
      if !form_answer.audit_certificate
        Notifiers::Shortlist::AuditCertificateRequest.new(form_answer).run
      end
    end
  end

  def unsuccessful_notification(award_year)
    # initialy shortlisted but then did not win
    award_year.form_answers.business.unsuccessful.each do |form_answer|
      if form_answer.audit_certificate
        Users::ShortlistedUnsuccessfulFeedbackMailer.notify(form_answer.id).deliver_later!
      end
    end
  end

  def all_unsuccessful_feedback(award_year)
    award_year.form_answers.unsuccessful.each do |form_answer|
{'fraction_non_alphanumeric': 0.07386482527725466, 'fraction_numerical': 0.0004184975936388366, 'mean_word_length': 4.413363533408834, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1081156', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1510, 'n_words': 222}