class UserPolicy
  attr_reader :current_user, :model

  def initialize(current_user, model)
    @current_user = current_user
    @user = model
  end

  class Scope
    def initialize(user, scope)
      @user  = user
      @scope = scope
    end

    def resolve
      if user.admin?
        scope.all
      else
        scope.all
        # scope.where(role: User.roles[:admin])
        # scope.all.where(id: @user.id)
      end
    end

    private

    attr_reader :user, :scope
  end

  def index?
    @current_user.admin? || true
  end

  def show?
    @current_user.admin? || @current_user == @user || true
  end

  def home?
    @current_user.admin? || @current_user == @user
  end

  def update?
    @current_user.admin?
  end

  def destroy?
    return false if @current_user == @user
    @current_user.admin?
  end
end
