(ns auto-ap.db.users
  (:require [auto-ap.db.utils :refer [get-conn query db->clj clj->db]]
            [clojure.edn :as edn]
            [clojure.java.jdbc :as j]
            [honeysql.core :as sql]
            [honeysql.helpers :as helpers]))

(defn data->fields [x]
  (-> x
      (merge (:data x))
      (dissoc :data)))

(defn fields->data [x]
  (-> x
      (assoc-in [:data :role] (:role x))
      (assoc-in [:data :name] (:name x))
      (assoc-in [:data :companies] (:companies x))
      (dissoc :role)
      (dissoc :name)
      (dissoc :companies)))

(def base-query (sql/build :select :*
                           :from :users))

(defn get-all []
  (map data->fields (query base-query)))
