         [ring.middleware.format-response :only [wrap-restful-response]]
         [ring.middleware.params :only (wrap-params)]
         [metrics.ring.instrument :only  (instrument)]
-        [swag.core :only (swagger-routes GET- POST- PUT- DELETE- defroutes-)]
+        [swag.core :only (swagger-routes http-codes GET- POST- PUT- DELETE- defroutes- errors)]
         [swag.model :only (defmodel wrap-swag defv defc)]
-        [celestial.common :only (import-logging)]
-        )
+        [celestial.common :only (import-logging)])
   (:require 
     [celestial.security :as sec]
     [celestial.persistency :as p]

    [compojure.route :as route])) 

(import-logging)

(def ^{:doc "see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html"}
  http-codes {:conflict 409 :success 200 :bad-req 400})

(defn resp
  "Http resposnse compositor"

                 (bad-req  {:msg (<< "Cannot create machine with missing type ~(e :t)}")}))) 
             )))

  (PUT- "/host/machine" [& ^:system props] {:nickname "updateHostMachine" :summary "Add Host machine" 
                                            :errorResponses (errors {:conflict "Host does not exist"}) }
        (let [host (get-in props [:machine :hostname])]
          (if-not (p/host-exists? host)
            (conflict {:msg "Host does not exists, use POST /host/machine first"}) 
            (do (p/register-host props) 
                (success {:msg "new host saved" :host host :props props})))))

  (DELETE- "/host/machine/:host" [^:string host] {:nickname "deleteHost" :summary "Delete Host" 
                                                  :errorResponses (errors {:bad-req "Host does not exist"})}
           (if (p/host-exists? host)
             (do (p/delete-host host) (success {:msg "Host deleted"}))
             (bad-req {:msg "Host does not exist"})))
