class Admin::Settings::AppleManagersController < Admin::Controller
  def show
    render_success :ok, json: config_props
  end

  def update
    if config.update(config_params)
      render_success :ok, json: config_props
    else
      render_error :unprocessable_entity, errors: config
    end
  end

  def export
    Reporting::Settings::AppleManagerJob.perform_async(current_school.id, current_user.id)
  end

  private
    def config
      @config ||= current_school.find_or_build_apple_manager_config
    end

    def config_params
      params.permit(:student_identifier, :staff_identifier, :location_id)
    end

    def config_props
      {
        student_identifier: config.student_identifier,
        staff_identifier: config.staff_identifier,
        location_id: config.location_id
      }
    end
end
