    [clojure.java.io :as io]
    [clojure.tools.logging :refer :all]
    [com.stuartsierra.component :refer [Lifecycle using]]
+   [manifold.deferred :as d]
    [schema.core :as s]
    [cheshire.core :as json]
    [byte-streams :as b]

(def URI "http://live-cdn.me-tail.net/cantor/api/wanda/garment-details/81e36a81-1921-4247-a8de-1ed7eb67840f?skus=nct_sandbox_dress_37_7cpxa7,nct_sandbox_trousers_2_5bahk2,nct_sandbox_jacket_4_btcjsf,nct_sandbox_coat_3_vxbetj,nct_sandbox_top_24_7k94td,nct_sandbox_skirt_15_04s5md,nct_sandbox_top_15_zwzenw")

(defn get-garments [uri]
  {:garments
   (let [response (deref (http/get uri))]
     (if (= (:status response) 200)
       (json/decode (b/to-string (:body response)) keyword)
       (throw (Exception. "Oh no!!!"))))})

(defn readf [env k params]
  (infof "Reading k is %s" k)
  (let [st @(:state env)]
    (if-let [[_ v] (find st k)]
      {:value v}
      {:value :not-found})))

(defn mutatef [env k params]
  (infof "MUTATE! %s" k)
  {})

(defn om-resource [parser app-state]
  (resource
   {:methods
    {:post

                        api]
  Lifecycle
  (start [component]
    (let [app-state (atom (get-garments URI))
          api (create-api (om/parser {:read readf :mutate mutatef}) app-state)]
      (assoc component
             :app-state app-state
