   alias Betazoids.Facebook
   alias Betazoids.Repo
 
+  @betazoids_thread_id "438866379596318"
+  # @sean_yu_long_lived_token "CAAMD90ZCeW1YBAE6tBMgPBeNhtbY0nUj6Il1A34dZAOqrSZCxwjsEu1uJjU8VQGrrOUc1DhLvXSfPCcW6ZBBDLsYG6ZAznoSi8l0t4qbKSDUZCSfmIFtDdnQMnGgkSa8DGAGkmpFMZAR4JIvAS4QmNgh2Q6e7VZCE04tWws4JGs2zdWf6taslUgKdCuHNXeEoqEZD"
+  @graph_explorer_token "CAACEdEose0cBAGf1yHYpoO2AI81xsKcq093zoVX0dwHpjAmV45A3YSOviPBWAAfoKHNidsnQRL1yi4yaHVK9a2ebU8pqf2pY5P4aZAeWqLYHDjCpYImnJn3pZAMQvFK14oGhwEqHktI6lB8EDbg9BfZAaCopbtDpA3fcdUkKD0hIoYtXtnIgna1GH2SzZBCHjhSjqbuIogZDZD"
 
   def start_link do
     Supervisor.start_link(__MODULE__, [], [name: Betazoids.Collector])

        message_count: length(res.comments),
        next_url: res.paging.next
      })
      {:ok, collector_log} = Repo.update(changeset)

      process_comments(res.comments, collector_log)
      collector_log
    end
  end

  defp fetch_next(collector_log) do
    case collector_log.done do
      true ->
        IO.puts "done fetching #{collector_log.message_count} messages in #{collector_log.fetch_count} fetches"
        {:ok, collector_log}
      false ->
        next_path = path_from_url(collector_log.next_url)
        %HTTPoison.Response{status_code: 200, body: body} = Facebook.get!(next_path)

          changeset = CollectorLog.changeset(collector_log, %{done: true})
          {:ok, collector_log} = Repo.update(changeset)
        else
          changeset = CollectorLog.changeset(collector_log, %{
            fetch_count: collector_log.fetch_count + 1,
            message_count: collector_log.message_count + length(comments),
            next_url: body.paging.next
          })

          # TODO(yu): This should be inside the transaction but it raises an
          # error for some reason
          {:ok, collector_log} = Repo.update(changeset)
          Repo.transaction fn ->
            process_comments(comments, collector_log)
          end
        end

        IO.puts """
        #{collector_log.fetch_count} -
        total: #{collector_log.message_count},
        add #{length(comments)} comments, first:
        #{List.first(comments).created_time}
        """

        :timer.sleep(1500)
        fetch_next(collector_log, tracer ++ [collector_log.fetch_count])
      true ->
        IO.puts """
        done fetching #{collector_log.message_count} messages
        in #{collector_log.fetch_count} fetches
        """

        {:ok, collector_log}
    end
  end

