     true))
 
 (defn validate [request {dsp :dsp status :status body :body}]
-  ;; TODO: validate id identity
+  ;; TODO: validate status before parse json
   (try
    (let [body (and body (json/parse-string body true))
          {:keys [id bidPrice advertiserId]} body

               true
               {:status :valid :response body})]
     (assoc ret :dsp dsp))
   (catch JsonParseException e {:status :invalid :reason "invalid JSON"})
   (catch Exception          e {:status :invalid :reason (format "validation process raised unexpected error: %s" e)})))

(defn log-validated [test arg]
  (let [{dsp :dsp res :response status :status} arg]



(defn auction [floor-price resps]
  (let [floor-price (and floor-price (* 1000 floor-price))]
   (case  (count resps)
     0 nil
     1 (let [{dsp :dsp res :response} (first resps)
             fp (or floor-price (:bidPrice res))]
         {:dsp dsp :response res :win-price (float (/ fp 1000))})
     (let [[{dsp :dsp res :response} {win-price :response}]
           (->> resps
                (shuffle)
                (sort-by (comp :bidPrice :response) >)
                (take 2))]
       {:dsp dsp :response res :win-price (float (/ (:bidPrice win-price) 1000))}))))

(defn click? [result response]
  (result (.indexOf (map :id advertisers) (:advertiserId response))))
