   [tag context config]
   {:pre  [(string? tag)]
    :post [(string? %)]}
-  (let [newtag     (capitalize-resource-type tag)
+  (let [newtag (capitalize-resource-type tag)
         newcontext {"node" (get context "node")
                     "type" newtag}]
     (str/lower-case (anonymize-leaf newtag :type newcontext config))))

  [aliases context config]
  {:pre  [(or (coll? aliases) (string? aliases) (nil? aliases))]
   :post [(= (type %) (type aliases))]}
  (if (coll? aliases)
    (vec (map #(anonymize-leaf % :title context config) aliases))
    (if (string? aliases)
      (anonymize-leaf aliases :title context config)
      aliases)))

(defn anonymize-parameter
  "Anonymize a parameter/value pair"
  [parameter context config]
  {:pre  [(coll? parameter)]
   :post [(coll? %)]}
  (let [[key val]  parameter
        newcontext (assoc-in context ["parameter-value"] val)]
    (case key
      ;; Metaparameters are special
      ("stage" "tag")        [key (anonymize-leaf val :title newcontext config)]
      "alias"                [key (anonymize-aliases val newcontext config)]
      ;; References get randomized in a special way
      ("require" "before"
       "notify" "subscribe") [key (anonymize-references val newcontext config)]
       ;; Everything else gets anonymized as per normal
       [(anonymize-leaf key :parameter-name newcontext config)
        (anonymize-leaf val :parameter-value newcontext config)])))

(defn anonymize-parameters
  "Anonymize the parameters keys and values for a resource"

        (str/replace param-name-pattern #(anonymize-leaf % :parameter-name context config))
        (str/replace title-pattern #(anonymize-leaf % :title context config)))))

(defn anonymize-catalog-resource
  [resource context config]
  {:pre  [(resource? resource)]
   :post [(resource? %)]}
  (let [newcontext {"node" (get context "node")
                    "title" (get resource "title")
                    "tags" (get resource "tags")
                    "file" (get resource "file")
                    "line" (get resource "line")
                    "type" (get resource "type")}]
    (-> resource
        (utils/update-when ["file"] anonymize-leaf :file newcontext config)
        (utils/update-when ["line"] anonymize-leaf :line newcontext config)
        (update "parameters" anonymize-parameters newcontext config)
        (update "tags" anonymize-tags newcontext config)
        (update "title" anonymize-leaf :title newcontext config)
        (update "type" anonymize-leaf :type newcontext config))))

(defn anonymize-catalog-resources
  [resources context config]
  {:pre  [(coll? resources)]
   :post [(coll? %)]}
  (map #(anonymize-catalog-resource % context config) resources))

(pls/defn-validated anonymize-resource-event :- resource-event-schema-str
  "Anonymize a resource event from a report"
