(ns auto-ap.client-selection
  (:require [clojure.string :as str]
            [malli.core :as mc]
            [malli.transform :as mt2]))

;; TODO remove this eventuall
(defn str->keyword [s]
  (if (string? s)
    (let [[ns k] (str/split s #"/")]
      (if (and ns k)
        (keyword ns k)
        (keyword s)))
    s))

(defn keyword->str [k]
  (subs (str k) 1))
(def client-selection-schema
  (mc/schema
   [:orn
    [:global [:enum :all :mine]]
    [:group-name [:map [:group :string]]]
    [:specific [:map [:selected [:vector nat-int?]]]]]))

(def client-selection-transformer
  (mt2/transformer
   mt2/json-transformer
   mt2/string-transformer
   (mt2/key-transformer {:encode keyword->str :decode str->keyword})))

;; END TODO