(ns auto-ap.integration.util
  (:require [datomic.client.api :as dc]
            [auto-ap.datomic :refer [client conn transact-schema]]
            [clj-time.core :as time]))

(defn wrap-setup
  [f]
  (require 'datomic.dev-local)
  (with-redefs [auto-ap.datomic/client (dc/client {:server-type :dev-local
                                                   :system      "test"})]
    (dc/create-database client {:db-name "test"})
    (with-redefs [auto-ap.datomic/conn (dc/connect client {:db-name "test"})]
      (transact-schema conn)
      (f)
      (dc/delete-database client {:db-name "test"}))))

(defn admin-token []
  {:user      "TEST ADMIN"
   :exp       (time/plus (time/now) (time/days 1))
   :user/role "admin"
   :user/name "TEST ADMIN"})

(defn user-token
  ([] (user-token 1))
  ([client-id]
                  {:user         "TEST USER"
                   :exp          (time/plus (time/now) (time/days 1))
                   :user/role    "user"
                   :user/name    "TEST USER"
                   :user/clients [{:db/id client-id}]}))
