(ns auto-ap.db.companies
  (:require [auto-ap.db.utils :refer [clj->db db->clj get-conn query execute!]]
            
            [clojure.edn :as edn]
            [clojure.java.jdbc :as j]
            [honeysql.core :as sql]
            [honeysql.helpers :as helpers]))
(def all-fields #{:name :email :data :id :signature-file})

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

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

(defn fields->data [x]
  (-> x
      (assoc-in [:data :bank-accounts] (:bank-accounts x))
      (assoc-in [:data :address] (:address x))
      (assoc-in [:data :locations] (:locations x))
      (dissoc :bank-accounts)
      (dissoc :locations)
      (dissoc :address)))

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