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

(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")

(s/def ::id (s/nilable string?))
(s/def ::name (s/nilable string?))
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
                                               :is-empty #(= % "")))))
(s/def ::phone (s/nilable string?))

(s/def ::contact (s/keys :opt-un [::name ::email ::phone ::id]))
