             [oc.storage.config :as config]
             [oc.storage.representations.media-types :as mt]
             [oc.storage.representations.org :as org-rep]
-            [oc.storage.resources.board :as board-res]))
+            [oc.storage.resources.board :as board-res]
+            [oc.storage.urls.board :as board-url]
+            [oc.storage.representations.entry :as entry-rep]))
 
 (def public-representation-props [:uuid :slug :name :access :promoted :entries :created-at :updated-at :links])
 (def representation-props (concat public-representation-props [:slack-mirror :author :authors :viewers :draft]))
 
-(defun url
-  ([org-slug board-slug :guard string? params :guard map?]
-    (str (url org-slug board-slug) "?start=" (:start params) "&direction=" (name (:direction params))))
-  ([org-slug board :guard map?] (url org-slug (:slug board)))
-  ([org-slug slug :guard string?]
-    (str "/orgs/" org-slug "/boards/" slug)))
+(defn- self-link 
+  ([org-slug slug] (hateoas/self-link (board-url/url org-slug slug) {:accept mt/board-media-type}))
 
-(defn- self-link 
-  ([org-slug slug] (hateoas/self-link (url org-slug slug) {:accept mt/board-media-type}))
-
-  ([org-slug slug options] (hateoas/self-link (url org-slug slug) {:accept mt/board-media-type} options)))
+  ([org-slug slug options] (hateoas/self-link (board-url/url org-slug slug) {:accept mt/board-media-type} options)))
 
 
-(defn- create-entry-link [org-slug slug] (hateoas/create-link (str (url org-slug slug) "/entries/")
+(defn- create-entry-link [org-slug slug] (hateoas/create-link (str (board-url/url org-slug slug) "/entries/")
                                                 {:content-type mt/entry-media-type
                                                  :accept mt/entry-media-type}))
 
-(defn- partial-update-link [org-slug slug] (hateoas/partial-update-link (url org-slug slug)
+(defn- partial-update-link [org-slug slug] (hateoas/partial-update-link (board-url/url org-slug slug)
                                               {:content-type mt/board-media-type
                                                :accept mt/board-media-type}))
 
 (defn- delete-link [org-slug slug]
-  (hateoas/delete-link (url org-slug slug)))
+  (hateoas/delete-link (board-url/url org-slug slug)))
 
 (defn- add-author-link [org-slug slug] 
-  (hateoas/add-link hateoas/POST (str (url org-slug slug ) "/authors/") {:content-type mt/board-author-media-type}))
+  (hateoas/add-link hateoas/POST (str (board-url/url org-slug slug ) "/authors/") {:content-type mt/board-author-media-type}))
 
 (defn- add-viewer-link [org-slug slug] 
-  (hateoas/add-link hateoas/POST (str (url org-slug slug ) "/viewers/") {:content-type mt/board-viewer-media-type}))
+  (hateoas/add-link hateoas/POST (str (board-url/url org-slug slug ) "/viewers/") {:content-type mt/board-viewer-media-type}))
 
 (defn- remove-author-link [org-slug slug user-id]
-  (hateoas/remove-link (str (url org-slug slug) "/authors/" user-id)))
+  (hateoas/remove-link (str (board-url/url org-slug slug) "/authors/" user-id)))
 
 (defn- remove-viewer-link [org-slug slug user-id]
-  (hateoas/remove-link (str (url org-slug slug) "/viewers/" user-id)))
+  (hateoas/remove-link (str (board-url/url org-slug slug) "/viewers/" user-id)))
 
 (defn- up-link [org-slug] (hateoas/up-link (org-rep/url org-slug) {:accept mt/org-media-type}))
 

  {:user-id user-id
   :links (if (= access-level :author) [(remove-viewer-link org-slug slug user-id)] [])})

(defn render-board-for-collection
  "Create a map of the board for use in a collection in the REST API"
  ([org-slug board] (render-board-for-collection org-slug board 0))

        first-activity-date (when activity? (or (:published-at first-activity) (:created-at first-activity)))
        next? (or (= (:direction data) :previous)
                  (= (:next-count data) config/default-activity-limit))
        next-url (when next? (board-url/url org board {:start last-activity-date :direction :before}))
        next-link (when next-url (hateoas/link-map "next" hateoas/GET next-url {:accept mt/board-media-type}))
        prior? (and start?
                    (or (= (:direction data) :next)
                        (= (:previous-count data) config/default-activity-limit)))
        prior-url (when prior? (board-url/url org board {:start first-activity-date :direction :after}))
        prior-link (when prior-url (hateoas/link-map "previous" hateoas/GET prior-url {:accept mt/board-media-type}))]
    (remove nil? [next-link prior-link])))

