 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Schema
 
-(def NameSpace s/Symbol)
-(def SchemaName s/Symbol)
 
-(def SchemaDescription
-  "Really just a map of symbols marking a namespace to
-  symbols naming schemata in that namespace"
-  {NameSpace (s/either SchemaName [SchemaName])})
-
-(def Schema
-  "An individual description"
-  s/Any)
-
-(def Schemata
-  "Really just so I have a meaningful name to call these things"
-  [Schema])
-
-(def ComponentName s/Keyword)
-(def ComponentInitializer (s/either s/Symbol [(s/one s/Symbol "name") s/Any]))
-(def InitializationMap {ComponentName ComponentInitializer})
-
-(def ComponentInstanceName
-  "TODO: Try redefining ComponentName as this
-I'm just not sure that'll work in non-sequences
-(such as when I'm using it as the key in a map)"
-  (s/one s/Keyword "name"))
-(def ComponentInstance (s/one s/Any "instance"))
-(def Component [ComponentInstanceName ComponentInstance])
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Internals
 
-(s/defn load-var :- s/Any
-  "Get the value of var inside namespace"
-  [namespace :- s/Symbol
-   var-name :- s/Symbol]
-  (let [sym (symbol (str namespace "/" var-name))]
-    (try
-      (eval sym)
-      (catch RuntimeException ex
-        ;; Logger isn't initialized yet
-        (print "Loading" var-name "from" namespace "failed")
-        (raise {:problem var-name
-                :reason ex})))))
-
-(s/defn require-schematic-namespaces!
-  "Makes sure all the namespaces where the schemata
-are found are available, so we can access the schemata"
-  [d :- SchemaDescription]
-  (dorun (map require (keys d))))
-
-(comment
-  (mapcat (fn [[k v]]
-            (println "Extracting" v "from ns" k)
-            (if (symbol? v)
-              (load-var k v)
-              (mapcat (partial load-var k) v)))
-          {'one '[schema-a schema-b]
-           'two 'schema-a}))
-
-(s/defn extract-schema :- Schemata
-  "Returns a seq of the values of the vars in each namespace"
-  [d :- SchemaDescription]
-  (mapcat (fn [[k v]]
-         (if (symbol? v)
-           [(load-var k v)]
-           (map (partial load-var k) v)))
-       d))
-
-(s/defn translate-schematics! :- Schemata
-  "require the namespace and load the schema specified in each.
-
-N.B. Doesn't even think about trying to be java friendly. No defrecord!"
-  [d :- SchemaDescription]
-  (require-schematic-namespaces! d)
-  (extract-schema d))
-
-;;; This actually returns a sequence of the pairs that form a Component.
-;;; So something like (concat [ComponentInstanceName ComponentInstance] ...)
-;;; Q: How can I specify that?
-;;; Q: Would it be better to use map instead of mapcat to build this
-;;; sequence, then concat it before I actually use it?
-(s/defn ^:always-validate initialize! :- [Component]
-  "require the individual namespaces and call each Component's constructor,
-returning a seq of name/instance pairs that probably should have been a map
-
-N.B. this returns key-value pairs that are suitable for passing to dependencies
-as the last argument of apply"
-  [descr :- InitializationMap
-   config-options :- {s/Any s/Any}]
-  (map (fn [[name ctor]]
-         ;; Called for the side-effects
-         ;; This should have been taken care of below,
-         ;; in the call to require-schematic-namespaces!
-         ;; But better safe than sorry
-         (-> ctor namespace symbol require)
-
-         (let [real-ctor (resolve ctor)
-               ;; Note the way this couples the Component name
-               ;; w/ the options.
-               ;; I'm not sure that's a bad thing
-               instance (real-ctor (name config-options))]
-           [name instance]))
-       descr))
-
-(s/defn ^:always-validate system-map! :- SystemMap
-  [descr :- InitializationMap
-   config-options :- {s/Any s/Any}]
-  (let [inited-pairs (initialize! descr config-options)
-        inited (apply concat inited-pairs)]
-    (apply component/system-map inited)))
-
-(s/defn ^:always-validate dependencies :- SystemMap
-  [inited :- SystemMap
-   descr :- {s/Keyword s/Any}]
-  (comment)
-  (let [ks (keys inited)]
-    (comment (log/debug "Preparing to build dependency tree for\n"
-                        (common/pretty inited)
-                        "with" (count ks) "keys\n"
-                        (common/pretty ks)
-                        "\nbased on the dependency description\n"
-                        (common/pretty descr))))
-  (component/system-using inited descr))
-
 (defn configure-logging!
-  "Doesn't belong here"
+  "Doesn't belong here
+TODO: Move to a Component in common"
   [log-file-name]
   (log/set-config!
    ;; TODO: This needs to rotate

;;; Public

;; TODO: What's the schema?
(defn combine-options
  [command-line-args system-description]
  (let [ctor-schemata (-> system-description :schemas translate-schematics!)]
    (cfg/assemble-configuration {:prefix "frereth"
                                 :schemas ctor-schemata
                                 ;; seq of absolute file paths that will

            [clojure.java.io :as io]
            [com.stuartsierra.component :as component]
            [com.frereth.common.util :as common]
            [component-dsl.system :as cpt-dsl]
            [io.aviso.config :as cfg]
            [ribol.core :refer (raise)]
            [schema.core :as s]
