 (ns ctia.stores.es.sighting
-  (:require [ctia.stores.es.crud :as crud]
+  (:require [ctia.lib.pagination :refer [list-response-schema]]
+            [ctia.stores.es.crud :as crud]
             [ctim.schemas
              [common :refer [Observable]]
              [sighting :refer [StoredSighting]]]


(def handle-delete-sighting (crud/handle-delete :sighting StoredSighting))

(defn es-paginated-list->paginated-list [paginated-list]
  (update-in paginated-list
             [:data]
             #(map es-stored-sighting->stored-sighting (es-coerce! %))))

  [s :- (s/maybe ESStoredSighting)]
  (when s (dissoc s :observables_hash)))

(s/defn handle-create-sighting :- StoredSighting
  [state realized]
  (let [create-fn (crud/handle-create :sighting ESStoredSighting)
        transformed (stored-sighting->es-stored-sighting realized)]
    (-> (create-fn state transformed)
        es-stored-sighting->stored-sighting)))

(s/defn handle-read-sighting :- (s/maybe StoredSighting)
  [state id]
  (let [read-fn (crud/handle-read :sighting ESStoredSighting)]
    (-> (read-fn state id)
        es-stored-sighting->stored-sighting)))
