class Pathwright::SupportJob
  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)
    props = {
      school_id: school.id,
      school_name: school.name,
      registrants: users.map { |u| { name: u.full_name, email: u.email } },
      course_name: course.name,
      start_date: Date.parse(date).strftime('%m/%d/%Y')
    }

    Mailgun::TemplateService.call(
      'Sycamore School <noreply@sycamoreschool.com>',
      'support@sycamoreeducation.freshdesk.com',
      "PathWright Course Registration - SS#{school.id}",
      'course_registration_internal',
      props
    )
  end
end
