   "http://www.elitetradingtool.co.uk/api/EliteTradingTool/Calculator")
 (def search-url 
   "http://www.elitetradingtool.co.uk/api/EliteTradingTool/Search")
-
+;; mapping for search-stations :search-type arg value to API value
+(def search-types {:buying "Station Buying"
+                   :selling "Station Selling"})
 ;;
 ;; Util methods
 ;;

(defn search-stations
  "Call the station searcher with various filters"
  [system-name &
   {:keys [callback commodity-id pad-size search-type search-range]
    :or {callback identity
         commodity-id nil
         pad-size "Small"
         search-type "Station Selling" ; or "Station Buying"; req for commodity-id
         search-range "15"}}]
  (let [request-body {:CurrentLocation system-name
                      :Commodity (if commodity-id true false)
                      :CommodityId commodity-id
                      :PadSize pad-size
                      :SearchType search-type
                      :SearchRange search-range}]
    (println request-body)
    (http/post 
      search-url
      {:headers {"Content-Type" "application/json"}
       :body request-body}
      (fn [{:keys [error body]}]
        (println body)
        (if error
          (do 
            (log "! Error searching" error "Request:" request-body)

(defn on-search
  "Packet handler for :search"
  [ch packet]
  (if-let [system (:system packet)]
    ; NB this also seems overly complicated
    (apply search-stations
           (flatten (conj [system] 
                          (calculate-packet-to-seq packet)
                          :callback #(to-client ch {:type :search-result
                                                    :result %}))))
    (client-error ch "Must specify system")))

;;
