 
 ;;; Response producing functions
 
-(defn allow [& verbs]
-  (log/debug "explaining allow verbs")
+(defn allow
+  "Indicate allowed verbs."
+  [& verbs]
+  (log/debugf "explaining allow verbs")
   {:status 405
    :headers {"Allow" (str/join "," verbs)}})
 
-(defn check-health []
+(defn check-health
+  "Indicate status of backing services."
+  []
+  (log/debugf "checking app health")
   (let [service-status (health/health-status)]
     (if (every? (fn [[_ {is :healthy}]] is) service-status)
       {:status 200 :body service-status}
       {:status 503 :body service-status})))
 
 (defn sample-source
-  "Retrieve some random sources"
+  "Retrieve some random sources."
   []
   (log/debugf "summarizing sources")
   {:status 200 :body (source/sample 10)})
 
 (defn get-source
-  "Search for a source and produce a response map."
+  "Search for source by ID."
   [source-id]
-  (log/debugf "lookup source: %s" source-id)
+  (log/debugf "get source: %s" source-id)
   (if-let [result (seq (source/search source-id))]
     {:status 200 :body result}
     {:status 404 :body []}))


(defn get-tiles
  "Get tiles containing point for given UBID and ISO8601 time range."
  [{{:keys [:ubid :x :y :acquired]} :params :as req}]
  (let [tile+    {:ubids (vectorize ubid)
                  :x (Integer/parseInt x)
                  :y (Integer/parseInt y)
                  :acquired (str/split acquired #"/")}
        tiles (tile/find tile+)]
    (log/debugf "GET /landsat/tiles")
    {:status 200 :body tiles}))

(defn get-tile-spec
  "Search for a source and produce a response map."
  [ubid {params :params :as req}]
  (if-let [results (first (tile-spec/query (merge {:ubid ubid} params)))]
    {:status 200 :body results}
    {:status 404 :body nil}))

(ns lcmap.aardvark.landsat
  "Resources and representations.

  This namespace contains all route definitions and functions
  transforming/validating requests. Other namespaces handle
  implementation details related to persistence and messaging."
  (:require [camel-snake-kebab.core :refer [->snake_case_keyword]]
            [camel-snake-kebab.extras :refer [transform-keys]]
            [cheshire.core :as json]
