class CanisterPolicy
  attr_reader :current_user, :model

  def initialize(current_user, model)
    @current_user = current_user || User.new
    @model = model
  end

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

    def resolve
      if user.admin?
        scope.all
      else
        scope.where(user: user)
      end
    end

    private

    attr_reader :user, :scope
  end


  def index?
    @current_user.admin?
  end

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

  def create?
    @current_user.admin?
  end

  def new?
    # @current_user.present?
    @current_user.admin?
  end

  def edit?
    @current_user.admin? || @current_user == @model.user
  end

  def update?
    @current_user.admin? || @current_user == @model.user
  end

  def destroy?
    @current_user.admin? || @current_user == @model.user
  end

end
