class Employee::Pathwright::EmployeesController < Employee::Controller
  def index
    render_success :ok, json: employees.map { |e| employee_props(e) }
  end

  def create
    user_ids = employees.where(id: params[:ids]).pluck(:id)
    Pathwright::SupportJob.perform_async(
      current_school.id,
      user_ids,
      course.id,
      params[:date]
    )
    Pathwright::RegistrantJob.perform_async(
      current_school.id,
      user_ids,
      course.id,
      params[:date]
    )
    render_success :ok, message: 'Registration Completed'
  end

  private
    def employees
      current_school.employees
        .where.not(email: [nil, ''])
        .where(active: true)
        .ordered
    end

    def course
      @course ||= Pathwright::Course.find_by(id: params[:course_id])
    end

    def employee_props(employee)
      {
        id: employee.id,
        first_name: employee.first_name,
        last_name: employee.last_name,
        email: employee.email
      }
    end
end
