;; next/genesis/validators/type-schema.sx
;;
;; Stage 5 of the validation pipeline per design §14. Validates
;; the activity's :object against the schema registered for its
;; :object :type in the define-registry projection.

(DefineValidator
  :name "type-schema"
  :doc "Looks up the object-type registration in the\n        define-registry projection, fetches its :schema body,\n        and evaluates it against (-> act :object). Returns true\n        when no object-type is named (some verbs carry no\n        :object) or when no schema is registered for the named\n        type (open-world default — Step 6 may tighten)."
  :predicate (fn
    (act)
    (let
      ((obj (-> act :object)))
      (cond
        (nil? obj)
        true
        (nil? (-> obj :type))
        true
        :else (let
          ((schema (-> (registry-lookup :object-types (-> obj :type)) :schema)))
          (if (nil? schema) true (apply-schema schema obj)))))))
