(ns wanijo.schema.domain
  (:require [clojure.spec.alpha :as spec]
            [wanijo.specs :as specs]
            [wanijo.attribute.domain :as domain-attr]
            [wanijo.infrastructure.neo4j :as neo4j]))

(spec/def ::name
  (spec/and ::specs/name (complement empty?)))
(spec/def ::assigned-to
  (spec/or :public empty?
           :assigned (spec/coll-of ::neo4j/uuid)
           :assigned-single ::neo4j/uuid))
(spec/def ::schema
  (spec/keys ::req-un [::name
                       ::specs/created-at
                       ::neo4j/uuid]))

(defn has-user-permission?
  [{public? :is_public
    user-permission :user_has_permission}]
  (or public? user-permission))

(spec/def ::req-attrs
  (spec/coll-of ::domain-attr/attribute))
(spec/def ::schema-with-req-attrs
  (spec/merge ::schema
              :req-un [::req-attrs]))
