class MetapursePolicy
  attr_reader :user, :metapurse

  def initialize(user, metapurse)
    @user = user || User.new
    @metapurse = metapurse
  end

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

    def resolve
      if user.admin?
        scope.all
      else
        scope.where(user_id: nil).or(scope.where(is_private: false)).or(scope.where(user_id: user.id))
        # scope.first
      end
    end

    private

    attr_reader :user, :scope
  end

  def index?
    true
  end

  def show?
    @user.admin? || @metapurse.user == @user || @metapurse.user == nil || @metapurse.is_private == false
  end

  def data?
    @user.admin? || @metapurse.user == @user || @metapurse.user == nil || @metapurse.is_private == false
  end

  def create?
    @user.admin? || @user.signed_in? || true
  end

  def new?
    @user.admin? || @user.signed_in? || true
  end

  def edit?
    @user.admin? || update?
  end

  def update?
    @user.admin? || @metapurse.user == @user || @metapurse.user == nil
  end

  def destroy?
    @user.admin? || @metapurse.user == @user || @metapurse.user == nil
  end

end
