(ns auto-ap.graphql.yodlee2
  (:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin enum->keyword]]
            [auto-ap.datomic.yodlee2 :as d-yodlee2]
            [auto-ap.time :refer [parse iso-date]]
            [auto-ap.utils :refer [dollars=]]
            [datomic.api :as d]
            [auto-ap.datomic :refer [uri remove-nils audit-transact conn]]
            [clj-time.coerce :as coerce]
            [clj-time.core :as time]
            [clojure.set :as set]
            [clojure.tools.logging :as log]))

(defn get-yodlee-provider-account-page [context args value]
  (assert-admin (:id context))  
  (let [args (assoc args :id (:id context))
        [yodlee-provider-accounts cnt] (d-yodlee2/get-graphql (<-graphql (assoc args :id (:id context))))]
    {:yodlee_provider_accounts (map ->graphql yodlee-provider-accounts)
     :total cnt
     :count (count yodlee-provider-accounts)
     :start (:start args 0)
     :end (+ (:start args 0) (count yodlee-provider-accounts))}))

(defn get-all-yodlee-provider-accounts [context args value]
  (assert-admin (:id context))
  (map
   ->graphql
   (first (d-yodlee2/get-graphql (assoc (<-graphql args)
                                         :count Integer/MAX_VALUE)))))

