(ns wanijo.public.routes
  (:require [compojure.core :refer [defroutes wrap-routes GET]]
            [wanijo.infrastructure.routing :refer [register!]]
            [wanijo.public.db :as db-public]
            [wanijo.public.view :as view-public]))

(defn index []
  (view-public/index))

(defn show-coc [coc-key]
  (view-public/show-coc (db-public/coc! coc-key)
                        (db-public/roles-with-levels-of-coc! coc-key)))

(defn show-modules [coc-key level-uuid]
  (view-public/show-modules
   (db-public/coc! coc-key)
   (db-public/level! level-uuid)
   (db-public/modules-with-comps! level-uuid)))

(defroutes routes
  (GET (register! :public-index "/public") [] (index))
  (GET (register! :public-coc-roles "/public/:coc") [coc] (show-coc coc))
  (GET (register! :public-role-modules "/public/:coc/:level")
       [coc level]
       (show-modules coc level)))
