(ns auto-ap.datomic.migrate.sales
  (:require [datomic.api :as d]
            [auto-ap.datomic :refer [uri]]))

(def norms-map {:add-orders {:txes [[{:db/ident :sales-order/external-id
                                      :db/doc "The client for the sale"
                                      :db/valueType :db.type/string
                                      :db/cardinality :db.cardinality/one
                                      :db/unique :db.unique/identity}

                                     {:db/ident :sales-order/client
                                      :db/doc "The client for the sale"
                                      :db/valueType :db.type/ref
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :sales-order/location
                                      :db/doc "The location of the sale"
                                      :db/valueType :db.type/string
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :sales-order/date
                                      :db/doc "The date the order was placed"
                                      :db/valueType :db.type/instant
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :sales-order/total
                                      :db/doc "The total amount on the sale"
                                      :db/valueType :db.type/double
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :sales-order/tax
                                      :db/doc "The tax on the sale"
                                      :db/valueType :db.type/double
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :sales-order/tip
                                      :db/doc "The tip on the sale"
                                      :db/valueType :db.type/double
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :sales-order/charges
                                      :db/doc "How the sale was paid"
                                      :db/valueType :db.type/ref
                                      :db/cardinality :db.cardinality/many
                                      :db/isComponent true}

                                     {:db/ident :sales-order/line-items
                                      :db/doc "What the person ordered"
                                      :db/valueType :db.type/ref
                                      :db/cardinality :db.cardinality/many
                                      :db/isComponent true}


                                     {:db/ident :charge/type-name
                                      :db/doc "The type of the charge"
                                      :db/valueType :db.type/string
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :charge/total
                                      :db/doc "The total amount on the charge"
                                      :db/valueType :db.type/double
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :charge/tax
                                      :db/doc "The tax on the charge"
                                      :db/valueType :db.type/double
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :charge/tip
                                      :db/doc "The tip on the charge"
                                      :db/valueType :db.type/double
                                      :db/cardinality :db.cardinality/one} 

                                     {:db/ident :order-line-item/item-name
                                      :db/doc "The type of the item"
                                      :db/valueType :db.type/string
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :order-line-item/total
                                      :db/doc "The total cost on the item"
                                      :db/valueType :db.type/double
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :order-line-item/tax
                                      :db/doc "The tax on the item"
                                      :db/valueType :db.type/double
                                      :db/cardinality :db.cardinality/one}

                                     {:db/ident :order-line-item/tip
                                      :db/doc "The tip on the item"
                                      :db/valueType :db.type/double
                                      :db/cardinality :db.cardinality/one} 

                                     ]]}

                :add-expected-deposits {:txes [[{:db/ident :expected-deposit/external-id
                                                 :db/doc "The external id for the deposit"
                                                 :db/valueType :db.type/string
                                                 :db/cardinality :db.cardinality/one
                                                 :db/unique :db.unique/identity}

                                                {:db/ident :expected-deposit/client
                                                 :db/doc "The client for the deposit"
                                                 :db/valueType :db.type/ref
                                                 :db/cardinality :db.cardinality/one}

                                                {:db/ident :expected-deposit/location
                                                 :db/doc "The location of the sale"
                                                 :db/valueType :db.type/string
                                                 :db/cardinality :db.cardinality/one}

                                                {:db/ident :expected-deposit/date
                                                 :db/doc "The date the deposit was initiated"
                                                 :db/valueType :db.type/instant
                                                 :db/cardinality :db.cardinality/one}

                                                {:db/ident :expected-deposit/total
                                                 :db/doc "The total amount on the deposit"
                                                 :db/valueType :db.type/double
                                                 :db/cardinality :db.cardinality/one}

                                                {:db/ident :expected-deposit/fee
                                                 :db/doc "The total fee on the deposit"
                                                 :db/valueType :db.type/double
                                                 :db/cardinality :db.cardinality/one}]]}


                :add-discounts {:txes [[{:db/ident :sales-order/discount
                                         :db/doc "The total amount on the sale"
                                         :db/valueType :db.type/double
                                         :db/cardinality :db.cardinality/one}

                                        {:db/ident :order-line-item/discount
                                         :db/doc "The total cost on the item"
                                         :db/valueType :db.type/double
                                         :db/cardinality :db.cardinality/one}]]}
                :add-category {:txes [[{:db/ident :order-line-item/category
                                        :db/doc "The item category"
                                        :db/valueType :db.type/string
                                        :db/cardinality :db.cardinality/one}]]}

                :add-other-types {:txes [[{:db/ident :sales-order/returns
                                           :db/doc "The returned amount on the sale"
                                           :db/valueType :db.type/double
                                           :db/cardinality :db.cardinality/one}

                                          {:db/ident :sales-order/service-charge
                                           :db/doc "The total cost on the item"
                                           :db/valueType :db.type/double
                                           :db/cardinality :db.cardinality/one}]]}

                :add-food-apps {:txes [[{:db/ident :ccp-processor/doordash
                                         :db/doc "Doordash identifier"}
                                        {:db/ident :ccp-processor/grubhub
                                         :db/doc "Grubhub identifier"}
                                        {:db/ident :ccp-processor/uber-eats
                                         :db/doc "Uber eats processor"}
                                        {:db/ident :ccp-processor/na
                                         :db/doc "No specific ccp processor"}

                                        {:db/ident :charge/processor
                                         :db/doc "Which food app processed this order"
                                         :db/valueType :db.type/ref
                                         :db/cardinality :db.cardinality/one}]]}
                :add-refunds {:txes [[{:db/ident :sales-refund/external-id
                                       :db/doc "The external id for the refund"
                                       :db/valueType :db.type/string
                                       :db/cardinality :db.cardinality/one
                                       :db/unique :db.unique/identity}

                                      {:db/ident :sales-refund/client
                                       :db/doc "The client for the refund"
                                       :db/valueType :db.type/ref
                                       :db/cardinality :db.cardinality/one}

                                      {:db/ident :sales-refund/location
                                       :db/doc "The location of the refund"
                                       :db/valueType :db.type/string
                                       :db/cardinality :db.cardinality/one}

                                      {:db/ident :sales-refund/date
                                       :db/doc "The date the refund was initiated"
                                       :db/valueType :db.type/instant
                                       :db/cardinality :db.cardinality/one}

                                      {:db/ident :sales-refund/total
                                       :db/doc "The total amount on the deposit"
                                       :db/valueType :db.type/double
                                       :db/cardinality :db.cardinality/one}

                                      {:db/ident :sales-refund/fee
                                       :db/doc "The total fee on the refund"
                                       :db/valueType :db.type/double
                                       :db/cardinality :db.cardinality/one}]]}
                :add-sales-date {:txes [[{:db/ident :expected-deposit/sales-date
                                          :db/doc "The date of sales the deposit was for"
                                          :db/valueType :db.type/instant
                                          :db/cardinality :db.cardinality/one}]]}
                :add-expected-deposit-status {:txes [[{:db/ident :expected-deposit/status
                                                       :db/doc "Whether the deposit has been cleared"
                                                       :db/valueType :db.type/ref
                                                       :db/cardinality :db.cardinality/one}
                                                      {:db/ident :expected-deposit-status/pending}
                                                      {:db/ident :expected-deposit-status/cleared}
                                                      {:db/ident :transaction/expected-deposit
                                                       :db/doc "If this transaction is a deposit, the deposit that we anticipated"
                                                       :db/valueType :db.type/ref
                                                       :db/cardinality :db.cardinality/one}]]}})

