 (ns com.palletops.bakery.jetty
   "Component for running jetty server.
-  Requires [ring/ring-jetty-adapter \"1.3.0\"].
   Provides an idempotent start and stop."
   (:require
    [com.palletops.api-builder.api :refer [defn-api]]

   [schema.core :as schema]))

(defn- start
  [{:keys [handler {:keys [port join?] :as config}]}]
  {:pre [handler port]}
  (jetty/run-jetty handler config))


  [{:keys [^org.eclipse.jetty.server.Server server]}]
  (.stop server))

(defrecord Jetty [handler config server]
  ILifecycle
  (start [component]
    (if server
      component
      (assoc component :server (start handler config))))
  (stop [component]
    (if server
      (do
