;; Blog service — inter-service data queries

(defquery post-by-slug (&key slug)
  "Fetch a single blog post by its URL slug."
  (service "blog" "get-post-by-slug" :slug slug))

(defquery post-by-id (&key id)
  "Fetch a single blog post by its primary key."
  (service "blog" "get-post-by-id" :id id))

(defquery posts-by-ids (&key ids)
  "Fetch multiple blog posts by comma-separated IDs."
  (service "blog" "get-posts-by-ids"
    :ids (map parse-int (filter (fn (s) (not (empty? s))) (split (str ids) ",")))))

(defquery search-posts (&key query page per-page)
  "Search blog posts by text query, paginated."
  (let ((result (service "blog" "search-posts"
                  :query query :page page :per-page per-page)))
    {"posts" (nth result 0) "total" (nth result 1)}))

(defquery page-config-ensure (&key container-type container-id)
  "Get or create a PageConfig for a container."
  (service "page-config" "ensure"
    :container-type container-type :container-id container-id))

(defquery page-config (&key container-type container-id)
  "Return a single PageConfig by container type + id."
  (service "page-config" "get-by-container"
    :container-type container-type :container-id container-id))

(defquery page-config-by-id (&key id)
  "Return a single PageConfig by primary key."
  (service "page-config" "get-by-id" :id id))

(defquery page-configs-batch (&key container-type ids)
  "Return PageConfigs for multiple container IDs (comma-separated)."
  (service "page-config" "get-batch"
    :container-type container-type
    :ids (map parse-int (filter (fn (s) (not (empty? s))) (split (str ids) ",")))))
