# frozen_string_literal: true

class DsnPolicy < ApplicationPolicy
  def index?
    current_user.present? && current_user.admin?
  end

  def show?
    current_user.present? && current_user.admin?
  end

  def create?
    current_user.present? && current_user.admin?
  end

  def new?
    create?
  end

  def update?
    current_user.present? && current_user.admin?
  end

  def edit?
    update?
  end

  def destroy?
    current_user.present? && current_user.admin?
  end

  def disable?
    current_user.present? && current_user.admin?
  end

  def enable?
    current_user.present? && current_user.admin?
  end

  class Scope < Scope
    def resolve
      if user&.admin?
        scope.all
      else
        scope.none
      end
    end
  end
end