(ns auto-ap.datomic.migrate.add-new-vendors
  (:require [datomic.api :as d]
            [auto-ap.datomic :refer [uri]]
            [clojure.data.csv :as csv]
            [clojure.java.io :as io]
            [clojure.string :as str])
  (:import [org.apache.commons.io.input BOMInputStream]))

(defn add-new-vendors [conn]
  [[]]
  #_(let [[header & rows] (-> "vendor-list.csv" (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv)
        headers (map read-string header)
        new-vendors [(reduce
                      (fn [rows r]
                        (conj rows (reduce
                                    (fn [r [header value]]
                                      (condp  = header
                                        [:vendor/address] r
                                        [:vendor/default-expense-account] (assoc-in r header (Integer/parseInt (str/replace value #"A" ""))) 
                                        [:vendor/invoice-reminder-schedule] r
                                        (assoc-in r header value)))
                                    {}
                                    (map vector headers r))))
                      []
                      rows)]]
    (println (ffirst new-vendors))
    new-vendors
    ))
