(ns buddho.core.dhamma.state
  "Facilities for managing dhamma registration in state memory."
  (:require [buddho.core.state.protocols :refer [value reference]]
            [buddho.core.state.idea :as idea]
            [buddho.core.state.property :as property]
            [buddho.core.dhamma.data :refer [make-dhamma]]))

(defn register-dhamma!
  "Register a dhamma."
  [name & {:keys [data meta is-aspect-of? asp-props transient]
           :as args}]
  (let [idea (idea/have-idea! "dhamma_")
        dhamma (make-dhamma name args)]
    (idea/update-idea! idea dhamma)
    (property/register-property! idea [:dhamma])))

(defn remove-dhamma! [dhamma]
  (idea/forget-idea! dhamma))

;; FIXME issues with this need to be at least considered
(defn update-dhamma! [dhamma fun]
  (idea/update-idea! (reference dhamma) (fun (value dhamma))))
