class Admin::TaskRequestsController < Admin::ApplicationController
  before_action :set_task_request, only: [:edit, :update, :show]

  def index
    @task_requests = task_requests.order_by_recent.paginate(page: params[:page])
  end

  def edit
  end

  def show
    @files = @task_request.files.paginate(page: params[:page])
  end

  def update
    if @task_request.update(task_request_params)
      redirect_to [:admin, :task_requests], notice: t(".notice")
    else
      render :edit
    end
  end

  private

  def task_request_params
    params.require(:task_request).permit(:status, :deliverable_url)
  end

  def task_requests
    policy_scope TaskRequest
  end

  def set_task_request
    @task_request = authorize policy_scope(TaskRequest).find(params[:id])
  end
end
