(ns auto-ap.datomic.clients
  (:require [datomic.api :as d]
            [auto-ap.datomic :refer [uri]]))

(defn get-all []
  
  (->> (d/q '[:find (pull ?e [* {:client/address [*]}])
              :where [?e :client/name]]
            (d/db (d/connect uri)))
       (map first)
       (map (fn [c]
              (update c :client/bank-accounts
                      (fn [bas]
                        (map (fn [ba]
                               (update ba :bank-account/type :db/ident ))
                             bas)))))))
(defn get-by-id [id]
  (->> 
   (d/query (-> {:query {:find ['(pull ?e [*])]
                         :in ['$ '?e]
                         :where [['?e]]}
                 :args [(d/db (d/connect uri)) id]}
                ))
   (first)
   (first)
   #_(map first)
   
   #_(first)))
