   (:require [futura.atomic :as atomic]
             [buddy.core.nonce :as nonce]
             [buddy.core.codecs :as codecs]
-            [catacumba.core :as ct])
+            [catacumba.impl.handlers :as handlers]
+            [catacumba.impl.context :as context])
   (:import clojure.lang.IAtom
            clojure.lang.IDeref
            clojure.lang.Counted

  (^:private modified? [_] "Check if session is modified"))

(defprotocol ISessionStorage
  (^:private load-data [_ key] "")
  (^:private persist-data [_ key data] ""))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Types


(alter-meta! #'->Session assoc :private true)

(defn- ->session
  "A session object constructor."
  ([sessionid] (->session sessionid {}))
  ([sessionid data]
   (Session. (atom data)
             sessionid
             (atomic/boolean false)
             (atomic/boolean false))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Storages
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn memory-storage
  "In memmory session storage constructor."
  []
  (let [internalstore (atom {})]
    (reify ISessionStorage
      (read-session [_ key]
        (let [key (keyword key)]
          (get @internalstore key nil)))
      (write-session [_ key data]
        (let [key (keyword key)]
          (swap! internalstore assoc key data)))
      (delete-session [_ key]
        (let [key (keyword key)]
          (swap! internalstore dissoc key))))))

(defn lookup-storage
  "A helper for create session storages with
  helpfull shortcuts."
  {:no-doc true}
  [storage]
  (case storage
    :inmemory (memory-storage)
