class Pathwright::RegistrantJob
  include Sidekiq::Worker

  def perform(school_id, user_ids, course_id, date)
    school = School.find(school_id)
    users = school.employees
      .where.not(email: [nil, ''])
      .where(active: true)
      .where(id: user_ids)
    @course = Pathwright::Course.find(course_id)
    @date = date

    users.each do |user|
      Mailgun::TemplateService.call(
        'Sycamore School <noreply@sycamoreschool.com>',
        user.email,
        'Sycamore School Microlearning Course Registration Confirmation',
        'course_registration_confirmation',
        props(user)
      )
    end
  end

  private
    def props(user)
      {
        course_name: @course.name,
        start_date: Date.parse(@date).strftime('%m/%d/%Y'),
        current_date: Date.today.strftime('%m/%d/%Y'),
        registrant_firstname: user.first_name
      }
    end
end
