 }}))
   )
 
-
-
 ;; spiking on yet another way of analyzing a configuration for errors
 
+;; TODO ignores descendent relationships, only works for the immediate
+;; type
 (defn predicate-rules-for-type [parent-type]
   (let [f (if parent-type #(vector % parent-type) identity)]
     (apply concat (mapv schema-rules (map f [:= :== :=>])))))

                         (spec 'AnotherInt string?)
                         (spec 'AnotherInt (ref-schema 'Integer))
                         (spec 'AndAnotherInt (ref-schema 'AnotherInt)))
  (doall (all-predicates 'AndAnotherInt))
  #_(leaf-pred? 'AnotherInt)
  #_(all-types 'AndAnotherInt)
  #_(all-types 'AndAnotherInt)
  #_(to-leaf-types 'AAnotherInt)
  #_(to-leaf-types 'AnotherInt)
  )

(defmulti apply-pred (fn [f v] (first f)))
(defmethod apply-pred :== [[_ pred] value] (= value pred))
(defmethod apply-pred := [[_ pred] value] (pred value))
(defmethod apply-pred :=> [[_ pred] value] (= (cond
                                                (map? value) :MAPP
                                                (sequence-like? value) :SEQQ
                                                :else :_____BAD)
                                              pred))

(defn type-check-pred [pred value state]
  (if-not (apply-pred pred value)
    (let [error {:Error-type :failed-predicate
                 :not (second pred)
                 :value value
                 :type-sig (:type-sig state)
                 :path     (:path state)}]
      [(if (not= (-> state :type-sig first)
                 (last pred))
         (assoc error :sub-type (last pred)) error)])
    {:success-type (last pred)}))

(defn type-check-value [parent-type value state]
  (if-let [preds (all-predicates parent-type)]
    (let [errors   (map #(type-check-pred % value state) preds)

     (group-by (fn [x] [:parent (second x) (first (nth x 2))]) (filter #(#{:?- :-} (second %)) spc))
     (group-by (juxt second first) spc))))



(defn fetch-pred [pred-type parent-type]
  (first (not-empty (schema-rules [pred-type parent-type])))
)

(defn leaf-pred? [parent-type]
  (or (fetch-pred :=  parent-type)
