 (defn create-snippet [consonant ref snippet]
   (t/transact! consonant
     (-> (t/begin :source (some-> ref :head :sha1))
-        (t/create :class "snippet" :properties (:properties snippet))
+        (t/create :class "snippet"
+                  :uuid (:uuid snippet)
+                  :properties (:properties snippet))
         (t/commit :target (if ref (:name ref) "HEAD")
                   :author {:name "Jannis Pohlmann" :email "jannis@xfce.org"}
                   :committer {:name "copaste" :email "copaste@copaste.org"}

;;;; Reads

(defmethod readf :copaste/refs
  [{:keys [consonant selector]} _ _]
  {:value (->> (s/get-refs consonant)
               vals
               (map #(select-keys % selector))
               (into []))})

(defmethod readf :copaste/snippets
  [{:keys [consonant selector]} _ {:keys [ref]}]
  {:value (->> (s/get-objects consonant (second ref) "snippet")
               (map object->om)
               (map #(select-keys % selector))
               (into []))})

;;;; Mutations


(defmethod mutatef 'copaste/save-snippet
  [{:keys [consonant]} _ {:keys [ref snippet]}]
  (let [snippet (om->object snippet)
        uuid (:uuid snippet)
        real-uuid (cond-> uuid(instance? TempId uuid) (-> :id str))]
    (println "uuid" uuid)
    (println "real-uuid" real-uuid)
    {:value {:keys [:copaste/refs :copaste/snippets]
             :tempids {[:snippet/by-uuid uuid]
                       [:snippet/by-uuid real-uuid]}}
     :action
     (fn []
       (let [ref (if ref ref (s/get-ref consonant "HEAD"))]
         (if (= uuid real-uuid)
           (update-snippet consonant ref snippet)
           (create-snippet consonant ref (assoc snippet :uuid real-uuid)))))}))
