(ns emptyhead.lib.context
  (:require [emptyhead.idea.memtag :as memtag]
            [emptyhead.thought.define :as def]
            [emptyhead.thought.crud :as thought]
            [emptyhead.idea.protocol :as prtc]))

(def/define! [:emptyhead :core :context]
  (fn [thought parent]
    (into [parent] (-> thought :data :proc-ret)))
  :constr-fn
  (fn [thought parent]
    {:data {:parent (memtag/uid-of parent)}}))

(defn new-context [& name]
  (let [ctx (thought/register-thought! [:emptyhead :core :context])]
    (-> ctx prtc/copy
        (assoc-in [:data :parent] (memtag/uid-of ctx))
        prtc/uncopy!)))
