 defmodule Riak.Connection do
   use GenServer
+  require Logger
 
   @spec start_link(Keyword.t) :: GenServer.on_start
   def start_link(opts) do

  end

  def fetch_type(pid, bucket, id) do
    GenServer.call(pid, {:fetch_type, bucket, id})
  end

  def update_type(pid, bucket, id, dt) do
    GenServer.call(pid, {:update_type, bucket, id, dt})
  end

  def search(pid, index, query, opts) do
    GenServer.call(pid, {:search, index, query, opts})
  end

  def delete(pid, bucket, id) do
    GenServer.call(pid, {:delete, bucket, id})
  end

  def handle_call({:fetch_type, bucket, id}, _from, s) do

          :pong ->
            :timer.send_after(s.heartbeat, self(), :heartbeat)
            {:noreply, s}
          {:error, reason} ->
            Logger.error("Riak.Connection: Heartbeat error: #{inspect(reason)}")
            :timer.send_after(s.heartbeat, self(), :heartbeat)
            {:noreply, s}
        end
      {false, _} ->
        :timer.send_after(s.heartbeat, self(), :heartbeat)
