json: enable JSON schema versioning

In a future commit I'm going to introduce a new JSON schema
("version 2"), so set the ground-work for that here.  There are
capabilities that are unable to be expressed in the current format, such
as prioritization of two groups both have Blink settings but at
different rates, but we want to retain backwards compatibility to any
existing configs.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ib4cb5761de1f80567a775cb15e8da921f539037e
diff --git a/manager/json-parser.hpp b/manager/json-parser.hpp
index 941ea4b..76d84c7 100644
--- a/manager/json-parser.hpp
+++ b/manager/json-parser.hpp
@@ -28,7 +28,7 @@
  *
  *  @return const Json - Json object
  */
-const Json readJson(const fs::path& path)
+Json readJson(const fs::path& path)
 {
 
     if (!fs::exists(path) || fs::is_empty(path))
@@ -98,18 +98,17 @@
     }
 }
 
-/** @brief Load JSON config and return led map
+/** @brief Load JSON config and return led map (JSON version 1)
  *
  *  @return LedMap - Generated an std::map of LedAction
  */
-const LedMap loadJsonConfig(const fs::path& path)
+const LedMap loadJsonConfigV1(const Json& json)
 {
     LedMap ledMap{};
     PriorityMap priorityMap{};
 
     // define the default JSON as empty
     const Json empty{};
-    auto json = readJson(path);
     auto leds = json.value("leds", empty);
 
     for (const auto& entry : leds)
@@ -147,6 +146,29 @@
     return ledMap;
 }
 
+/** @brief Load JSON config and return led map
+ *
+ *  @return LedMap - Generated an std::map of LedAction
+ */
+const LedMap loadJsonConfig(const fs::path& path)
+{
+    auto json = readJson(path);
+
+    auto version = json.value("version", 1);
+    switch (version)
+    {
+        case 1:
+            return loadJsonConfigV1(json);
+
+        default:
+            lg2::error("Unsupported JSON Version: {VERSION}", "VERSION",
+                       version);
+            throw std::runtime_error("Unsupported version");
+    }
+
+    return LedMap{};
+}
+
 /** @brief Get led map from LED groups JSON config
  *
  *  @param[in] config - Path to the JSON config.