     (seq? v) (summerize-seq v)
     :else (pr-str v)))
 
+(defn summerize-value-unwrap-top [v]
+  (let [res (summerize-value v)]
+    (if (map? v)
+      (nth res 3)
+      res)))
+
+#_(pprint-document (summerize-value-unwrap-top {:aasdfasdfasdf 1
+                                                :basdfasdfasdf 2
+                                                :casdfasdfasdf 2
+                                                :dasdfasdfasdf 2})
+                   {:width 10})
+
 (defn format-key
   ([k] (pr-str k))
   ([k colr] (color (format-key k) colr)))

(defn format-value
  ([value] (summerize-value value))
  ([value colr] (color (format-value value) colr)))

(defn format-key-value [ky fk fv message]
  [:group
   fk 
   " "
   [:nest (inc (count (pr-str ky))) fv]
   [:line " <- "]
    (color message :underline :magenta)
    :line])

(defmulti print-error :Error)

(defmethod print-error :unknown-key [{:keys [key value path type-sig] :as error}]
  (pprint-document (print-path-error error
                                     (format-key-value
                                      key
                                      (format-key key :red)
                                      (format-value value)
                                      (str "^ key " (pr-str key) " not recognized")))
                   {:width 40}))

(defmethod print-error :missing-required-key [{:keys [path value type-sig] :as error}]
  (pprint-document (print-path-error error
                                     [:group
                                      (color (pr-str (first path)) :red)
                                      [:line " <- "]
                                      (color (str "^ required key " (pr-str (first path)) " is missing")
                                             :underline :magenta)
                                      :line]
                                     (document-key (first type-sig) (first path))
                                     )
                   {:width 40}))

(defn failed-predicate [{:keys [path value type-sig orig-config] :as error}]
  (if (parent-is-sequence? error)
    (let [orig-config-seq (get-in orig-config (reverse (rest path)))]
      (pprint-document (print-path-error error 
                                         [:nest 2

                                          (concat
                                           [:group (format-key (second path))  " [ " ]
                                           [[:nest (+ 3 (count (str (second path))))
                                             
                                             (cons :group
                                                   (interpose :line (map-indexed 
                                                             #(if (= (first path) %1)
                                                                (color (pr-str %2) :red)
                                                                (pr-str %2))
                                                             orig-config-seq)
                                                      ))]]
                                           #_(format-value value :red)
                                           [" ] "])]
                                         (document-key (first (rest (rest type-sig))) (second path)))
                       {:width 40}))
    (pprint-document (print-path-error error
                                       (format-key-value
                                        (first path)
                                        (format-key (first path) :bold)
                                        (format-value value :red)
                                        (str "^ key " (pr-str (first path)) " has wrong value"))
                                       (document-key (first (rest type-sig)) (first path)))
                     {:width 40})))

(defmethod print-error :failed-predicate [error] (failed-predicate error))
(defmethod print-error :combined-failed-predicate [error] (failed-predicate error))

(defmethod print-error :should-not-be-empty [{:keys [path value type-sig orig-config] :as error}]
  (pprint-document (print-path-error error
                                     (format-key-value
                                      (first path)
                                      (format-key (first path) :bold)
                                      (format-value value :red)
                                      (str "^ key " (pr-str (first path)) " should not be empty"))
                                     (document-key (first type-sig) (first path)))
                   {:width 40}))

(defmethod print-error :misplaced-key [{:keys [key correct-paths correct-type orig-error orig-config type-sig] :as error}]
  (pprint-document (print-wrong-path-error
                    error
                    (format-key-value
                     key
                     (format-key key :red)
                     (format-value (:value orig-error))
                     (str "^ key " (format-key key) " is on the wrong path"))
                    (document-key (first correct-type) key))
                   {:width 40}))

(defmethod print-error :misspelled-misplaced-key [{:keys [key correct-paths correction correct-type orig-error orig-config type-sig] :as error}]
  (pprint-document (print-wrong-path-error
                    error
                    (format-key-value
                     key
                     (format-key key :red)
                     (format-value (:value orig-error))
                     (str "^ key " (format-key key) " is mispelled and on the wrong path"))
                    (document-key (first correct-type) correction))
                   {:width 40}))

(defmethod print-error :wrong-position-for-value [{:keys [key value correct-paths correct-type orig-error orig-config type-sig] :as error}]
  (pprint-document (print-wrong-path-error
                    (assoc error :correction (first (first correct-paths)))
                    [:group
                     (format-value value :bold)
                     [:line " <- "]
                     (str "^ value is in the wrong place")]
                    (document-key (first correct-type) (first (first correct-paths))))
                   {:width 40}))

(defmethod print-error :failed-key-predicate [{:keys [key value orig-error orig-config type-sig path] :as error}]
  (pprint-document (print-path-error error
                                     (format-key-value
                                      key
                                      (format-key key :red)
                                      (format-value value)
                                      (str "^ key " (pr-str key) " failed key predicate"))
                                     (document-key (first (rest type-sig)) (first (rest path))))
                   {:width 40}))

(defn document-all [parent-typ all-keys]
  (doall


(defmethod error-help-message :wrong-position-for-value
  [{:keys [key correction correct-paths]}]
  [:group "The value below is most likely in the wrong place in your config."])

#_(pp)
;; printing

(defn format-map [leaf-node]
  [:group "{"
   [:nest 2
    :line
    leaf-node]
   "}"])

(defn print-path-helper [[x & xs :as path] leaf-node]
  (if (empty? path)
    leaf-node
    (let [array? (and (number? x) (zero? x))]
      [:group
       (if array? "[" "{")
       (if array?
         (print-path-helper xs leaf-node)
         [:nest 2
          :line
          (list
           (if array? "" [:span [:text (pr-str x)] " "])
           (print-path-helper xs leaf-node))])
       (if array? "]" "}")])))

;; print-path ignores the initial wrapping 
(defn print-path [[x & xs :as path] leaf-node]
  (if (empty? path)
    leaf-node
    (let [array? (and (number? x) (zero? x))]
      (if array?
      (print-path-helper xs leaf-node)
      [:group
       (if array? "" [:span [:text (pr-str x)] " "])
       (print-path-helper xs leaf-node)]))))



#_(fipp-format-data {:asdf {:Asdf {:asdf 1 :asdfff 2}}}) 


(print-path [] [:text "3"])
#_(pprint-document (print-path [:asdf 0 :asdfff :asdf 0 ] [:text "3"] )
                 {:width 20} )

(defn blank-document? [x]
  (or (nil? x)
