(ns remove-old-yodlee)

(def account->provider-account
  (->> @in-memory-cache

       (reduce
        (fn [acc {:keys [id accounts]}]
          (reduce
           (fn [acc a]
             (assoc acc (:id a) id))

           acc
           accounts)

          )
        {})))

(def used-provider-accounts
  (->> (datomic.api/query {:query {:find ['?y]
                                                             :in ['$]
                                                             :where ['[_ :bank-account/yodlee-account-id ?y]]}
                                                     :args [(datomic.api/db (datomic.api/connect auto-ap.datomic/uri))]})
                                 (map first)
                                 (map account->provider-account)
                                 set
                                 ))

(def all-provider-accounts (set (map :id @in-memory-cache)))

(clojure.set/difference all-provider-accounts used-provider-accounts)

(->> [17891145 14187174 14264733 14274237 16681522 18612051 17796307 18643735
      14187073 17754737 16153006 14565664 15941583 18621649 14187279 14187177
      18652162 17892740 14187420 15613426 14187503 16604611 18611904 14180564
      16153014 15942027 17574983 14186984 14180087 18651698 18645515 18472838
      15735320]
     (map (by :id @in-memory-cache))
     (mapcat :accounts)
     (mapcat :dataset)
     (map :additionalStatus)
     #_(map :lastUpdated)
     )


