(ns auto-ap.entities.vendors
  (:require [clojure.spec.alpha :as s]
            [clojure.string :as str]
            [auto-ap.entities.contact :as contact]
            [auto-ap.entities.address :as address]))

(s/def ::id string?)
(s/def ::identifier (s/nilable string?)) (s/def ::required-identifier (s/and string?
                                    #(not (str/blank? %))))

(s/def ::name ::required-identifier)
(s/def ::print-as (s/nilable string?))

(s/def ::invoice-reminder-schedule (s/nilable #{"Weekly" "Never" nil}))

(s/def ::primary-contact (s/nilable ::contact/contact))
(s/def ::secondary-contact (s/nilable ::contact/contact))
(s/def ::address (s/nilable ::address/address))
(s/def ::default-expense-account int?)

(s/def ::code (s/nilable string?))

(s/def ::vendor (s/keys :req-un [::name
                                 ::default-expense-account]
                        :opt-un [::code
                                 ::id
                                 ::print-as
                                 ::invoice-reminder-schedule
                                 ::primary-contact
                                 ::secondary-contact
                                 ::address]))


(def vendor-spec (apply hash-map  (drop 1 (s/form ::vendor))))
(def all-keys (map #(keyword (name %)) (concat (:req-un vendor-spec) (:opt-un vendor-spec))))
