class SocialLinkPolicy
  attr_reader :user, :model

  def initialize(user, model)
    @user = user || User.new
    @social_link = 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?
    @user.admin? || true
  end

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

  def new?
    @user.signed_in?
  end

  def create?
    @user.signed_in?
  end

  def edit?
    update?
  end

  def update?
    @user.admin? || @user == @social_link.user
  end

  def destroy?
    @user.admin? || @user == @social_link.user
  end
end
