 defmodule Wizard.Sharepoint.Subscriber.Syncer do
   alias Wizard.Repo
   alias Ecto.Multi
-  alias Wizard.Sharepoint.{Api, Authorization, Drive, Service, Site}
+  alias Wizard.Sharepoint.{Api, Authorization, Drive, Item, Service, Site}
+
+  import Ecto.Changeset, only: [put_assoc: 3, fetch_field: 2]
 
   use GenServer
   require Logger

    |> Repo.transaction()
  end

  defp process_item(item, multi, _drive) do
    Logger.debug("processing: #{inspect(item)}")
    # TODO: actually build a Multi.insert for this item
    multi
  end

  defp update_drive(drive, delta_link) do

    "#{endpoint_uri}/v2.0/drives/#{drive_id}/root:/:/delta"
  end

  defp fetch(%{done: true} = state), do: {:ok, state} # NOTE: done

  defp fetch(%{drive: drive, authorization: auth, delta_link: nil, next_link: nil} = state) do
    Api.get(delta_link_url(drive), access_token(auth))
