             [metabase.util :as u])
   (:import (clojure.lang Keyword)))
 
-(declare parse-aggregation
+(declare expand-macros
+         parse-aggregation
          parse-breakout
          parse-fields
          parse-filter

                                                                      (parse-order-by-direction direction)))
(defparser parse-order-by
  subclauses (mapv parse-order-by-subclause subclauses))

    (binding [*original-query-dict* query-dict]
      ;; TODO - we should parse the Page clause so we can validate it
      ;; And convert to a limit / offset clauses
      (-> query-dict
          ;; expand/resolve macro type clauses first (metrics & segments)
          expand-macros
          ;; now parse the base clauses, fields, & values
          (update :query #(-<> (assoc %
                                 :aggregation (parse-aggregation (:aggregation %))
                                 :breakout    (parse-breakout    (:breakout %))
                                 :fields      (parse-fields      (:fields %))
                                 :filter      (parse-filter      (:filter %))
                                 :order_by    (parse-order-by    (:order_by %)))
                               (set/rename-keys <> {:order_by     :order-by
                                                    :source_table :source-table})
                               (m/filter-vals non-empty-clause? <>)))))))


;; ## -------------------- Field + Value --------------------
