             [ring.middleware.gzip :refer [wrap-gzip]]
             [swarmpit.authentication :refer [wrap-authentication]]
             [swarmpit.authorization :refer [wrap-authorization]]
-            ;[swarmpit.handler :as handler :refer :all]
             [swarmpit.event.handler :refer :all]
             [org.httpkit.server :refer [run-server]]
-            ;[bidi.ring :refer [make-handler]]
-            ;[bidi.bidi :refer [match-pair match-route*]]
             [clojure.tools.logging :as log]
             [swarmpit.routes :as routes]
             [swarmpit.setup :as setup]
             [swarmpit.database :as db]
             [swarmpit.agent :as agent]
-
-
             [reitit.ring :as ring]
             [reitit.coercion.spec]
             [reitit.swagger :as swagger]

            [reitit.ring.coercion :as coercion]
            [reitit.dev.pretty :as pretty]
            [reitit.ring.middleware.muuntaja :as muuntaja]
            [reitit.ring.middleware.exception :as exception]
            [reitit.ring.middleware.parameters :as parameters]
            [muuntaja.core :as m]

            ))

(defn wrap-client-exception
  [handler]

        {:status 500
         :body   (Throwable->map e)}))))

(def app
  (ring/ring-handler
    (ring/router
      routes/backend
      {:exception pretty/exception
       :conflicts nil
       :data      {:coercion   reitit.coercion.spec/coercion
                   :muuntaja   m/instance
                   :middleware [;; authentication
                                wrap-authentication
                                ;; authorization
                                wrap-authorization
                                ;; negotiation, request decoding and response encoding
                                muuntaja/format-middleware
                                ;; swagger feature
                                swagger/swagger-feature
                                ;; query-params & form-params
                                parameters/parameters-middleware
                                ;; exception handling
                                wrap-client-exception
                                wrap-fallback-exception
                                ;; coercing response bodys
                                coercion/coerce-response-middleware
                                ;; coercing request parameters
                                coercion/coerce-request-middleware]}})
    (ring/routes
      (swagger-ui/create-swagger-ui-handler
        {:path   "/"
         :config {:validatorUrl     nil
                  :operationsSorter "alpha"}})
      (ring/create-default-handler))))

