 (ns clj-money.import
   (:refer-clojure :exclude [update])
   (:require [clojure.pprint :refer [pprint]]
-            [clj-money.util :refer [pprint-and-return-l]]
+            [clj-money.util :refer [pprint-and-return
+                                    pprint-and-return-l]]
+            [clj-money.validation :as validation]
             [clj-money.models.users :as users]
             [clj-money.models.entities :as entities]
             [clj-money.models.accounts :as accounts]

  is created"
  [storage-spec user entity-name input source-type]
  (with-transacted-storage [s storage-spec]
    (let [entity (entities/find-or-create s user  entity-name)
          context (atom {:storage s
                         :accounts {}
                         :entity-id (:id entity)})]
      (read-source source-type input (->Callback (fn [account] (swap! context #(import-account % account)))
                                                 (fn [transaction] (swap! context #(import-transaction % transaction))))))))

        parent-id (get-in context [:accounts original-parent-id])
        to-create (cond-> account
                    true
                    (assoc :entity-id (-> context :entity :id))

                    true
                    (dissoc :id)
