Using enum class instead of string in more places

ReportingType and ReportUpdates are now used as enum class in more
places than before. Changed how this two fields are stored in
persistent configuration. Increased Report::Version to break backward
compatibility. Updated unit tests to verify changed functionality.

Tested:
- All existing tests are passing

Change-Id: I55db205aefbe2b5a69fb7a31ccf11885aaecaaf2
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/src/types/collection_time_scope.hpp b/src/types/collection_time_scope.hpp
index d2694d2..90c4fd3 100644
--- a/src/types/collection_time_scope.hpp
+++ b/src/types/collection_time_scope.hpp
@@ -29,13 +29,14 @@
 inline CollectionTimeScope
     toCollectionTimeScope(std::underlying_type_t<CollectionTimeScope> value)
 {
-    return toEnum<CollectionTimeScope, CollectionTimeScope::point,
-                  CollectionTimeScope::startup>(value);
+    return toEnum<CollectionTimeScope,
+                  minEnumValue(convDataCollectionTimeScope),
+                  maxEnumValue(convDataCollectionTimeScope)>(value);
 }
 
-inline CollectionTimeScope stringToCollectionTimeScope(const std::string& value)
+inline CollectionTimeScope toCollectionTimeScope(const std::string& value)
 {
-    return stringToEnum(convDataCollectionTimeScope, value);
+    return toEnum(convDataCollectionTimeScope, value);
 }
 
 inline std::string enumToString(CollectionTimeScope value)
@@ -43,4 +44,4 @@
     return std::string(enumToString(convDataCollectionTimeScope, value));
 }
 
-} // namespace utils
\ No newline at end of file
+} // namespace utils
diff --git a/src/types/operation_type.hpp b/src/types/operation_type.hpp
index a4f085c..5665e79 100644
--- a/src/types/operation_type.hpp
+++ b/src/types/operation_type.hpp
@@ -34,13 +34,13 @@
 inline OperationType
     toOperationType(std::underlying_type_t<OperationType> value)
 {
-    return toEnum<OperationType, OperationType::single, OperationType::sum>(
-        value);
+    return toEnum<OperationType, minEnumValue(convDataOperationType),
+                  maxEnumValue(convDataOperationType)>(value);
 }
 
-inline OperationType stringToOperationType(const std::string& value)
+inline OperationType toOperationType(const std::string& value)
 {
-    return stringToEnum(convDataOperationType, value);
+    return toEnum(convDataOperationType, value);
 }
 
 inline std::string enumToString(OperationType value)
diff --git a/src/types/report_action.hpp b/src/types/report_action.hpp
new file mode 100644
index 0000000..44348f2
--- /dev/null
+++ b/src/types/report_action.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "utils/conversion.hpp"
+
+#include <array>
+#include <cstdint>
+#include <string_view>
+#include <type_traits>
+
+enum class ReportAction : uint32_t
+{
+    emitsReadingsUpdate,
+    logToMetricReportsCollection
+};
+
+namespace utils
+{
+
+constexpr std::array<std::pair<std::string_view, ReportAction>, 2>
+    convDataReportAction = {
+        {std::make_pair<std::string_view, ReportAction>(
+             "EmitsReadingsUpdate", ReportAction::emitsReadingsUpdate),
+         std::make_pair<std::string_view, ReportAction>(
+             "LogToMetricReportsCollection",
+             ReportAction::logToMetricReportsCollection)}};
+
+inline ReportAction toReportAction(std::underlying_type_t<ReportAction> value)
+{
+    return toEnum<ReportAction, minEnumValue(convDataReportAction),
+                  maxEnumValue(convDataReportAction)>(value);
+}
+
+inline ReportAction toReportAction(const std::string& value)
+{
+    return toEnum(convDataReportAction, value);
+}
+
+inline std::string enumToString(ReportAction value)
+{
+    return std::string(enumToString(convDataReportAction, value));
+}
+
+} // namespace utils
\ No newline at end of file
diff --git a/src/types/report_types.hpp b/src/types/report_types.hpp
index b0b1a69..9d4a160 100644
--- a/src/types/report_types.hpp
+++ b/src/types/report_types.hpp
@@ -39,61 +39,3 @@
 
 ReadingParameters
     toReadingParameters(const std::vector<LabeledMetricParameters>& labeled);
-
-enum class ReportUpdates
-{
-    Overwrite = 0,
-    AppendStopsWhenFull,
-    AppendWrapsWhenFull,
-    NewReport
-};
-
-namespace details
-{
-constexpr std::array<std::pair<std::string_view, ReportUpdates>, 5>
-    convDataReportUpdates = {
-        std::make_pair("Overwrite", ReportUpdates::Overwrite),
-        std::make_pair("AppendStopsWhenFull",
-                       ReportUpdates::AppendStopsWhenFull),
-        std::make_pair("AppendWrapsWhenFull",
-                       ReportUpdates::AppendWrapsWhenFull),
-        std::make_pair("NewReport", ReportUpdates::NewReport)};
-
-} // namespace details
-
-inline ReportUpdates stringToReportUpdates(const std::string& str)
-{
-    return utils::stringToEnum(details::convDataReportUpdates, str);
-}
-
-inline std::string reportUpdatesToString(ReportUpdates v)
-{
-    return std::string(utils::enumToString(details::convDataReportUpdates, v));
-}
-
-enum class ReportingType
-{
-    OnChange = 0,
-    OnRequest,
-    Periodic
-};
-
-namespace details
-{
-constexpr std::array<std::pair<std::string_view, ReportingType>, 3>
-    convDataReportingType = {
-        std::make_pair("OnChange", ReportingType::OnChange),
-        std::make_pair("OnRequest", ReportingType::OnRequest),
-        std::make_pair("Periodic", ReportingType::Periodic)};
-
-} // namespace details
-
-inline ReportingType stringToReportingType(const std::string& str)
-{
-    return utils::stringToEnum(details::convDataReportingType, str);
-}
-
-inline std::string reportingTypeToString(ReportingType v)
-{
-    return std::string(utils::enumToString(details::convDataReportingType, v));
-}
diff --git a/src/types/report_updates.hpp b/src/types/report_updates.hpp
new file mode 100644
index 0000000..a47e8fb
--- /dev/null
+++ b/src/types/report_updates.hpp
@@ -0,0 +1,62 @@
+#pragma once
+
+#include "utils/conversion.hpp"
+
+#include <sdbusplus/exception.hpp>
+
+#include <array>
+#include <cstdint>
+#include <string_view>
+#include <type_traits>
+
+enum class ReportUpdates : uint32_t
+{
+    overwrite,
+    appendStopsWhenFull,
+    appendWrapsWhenFull,
+    newReport
+};
+
+namespace utils
+{
+
+template <>
+struct EnumTraits<ReportUpdates>
+{
+    [[noreturn]] static void throwConversionError()
+    {
+        throw sdbusplus::exception::SdBusError(
+            static_cast<int>(std::errc::invalid_argument),
+            "Invalid ReportUpdates");
+    }
+};
+
+constexpr std::array<std::pair<std::string_view, ReportUpdates>, 4>
+    convDataReportUpdates = {
+        {std::make_pair<std::string_view, ReportUpdates>(
+             "Overwrite", ReportUpdates::overwrite),
+         std::make_pair<std::string_view, ReportUpdates>(
+             "AppendStopsWhenFull", ReportUpdates::appendStopsWhenFull),
+         std::make_pair<std::string_view, ReportUpdates>(
+             "AppendWrapsWhenFull", ReportUpdates::appendWrapsWhenFull),
+         std::make_pair<std::string_view, ReportUpdates>(
+             "NewReport", ReportUpdates::newReport)}};
+
+inline ReportUpdates
+    toReportUpdates(std::underlying_type_t<ReportUpdates> value)
+{
+    return toEnum<ReportUpdates, minEnumValue(convDataReportUpdates),
+                  maxEnumValue(convDataReportUpdates)>(value);
+}
+
+inline ReportUpdates toReportUpdates(const std::string& value)
+{
+    return toEnum(convDataReportUpdates, value);
+}
+
+inline std::string enumToString(ReportUpdates value)
+{
+    return std::string(enumToString(convDataReportUpdates, value));
+}
+
+} // namespace utils
diff --git a/src/types/reporting_type.hpp b/src/types/reporting_type.hpp
new file mode 100644
index 0000000..ae0b60a
--- /dev/null
+++ b/src/types/reporting_type.hpp
@@ -0,0 +1,58 @@
+#pragma once
+
+#include "utils/conversion.hpp"
+
+#include <sdbusplus/exception.hpp>
+
+#include <array>
+#include <cstdint>
+#include <string_view>
+#include <type_traits>
+
+enum class ReportingType : uint32_t
+{
+    periodic,
+    onRequest,
+    onChange
+};
+
+namespace utils
+{
+
+template <>
+struct EnumTraits<ReportingType>
+{
+    [[noreturn]] static void throwConversionError()
+    {
+        throw sdbusplus::exception::SdBusError(
+            static_cast<int>(std::errc::invalid_argument),
+            "Invalid reportingType");
+    }
+};
+
+constexpr std::array<std::pair<std::string_view, ReportingType>, 3>
+    convDataReportingType = {{std::make_pair<std::string_view, ReportingType>(
+                                  "Periodic", ReportingType::periodic),
+                              std::make_pair<std::string_view, ReportingType>(
+                                  "OnRequest", ReportingType::onRequest),
+                              std::make_pair<std::string_view, ReportingType>(
+                                  "OnChange", ReportingType::onChange)}};
+
+inline ReportingType
+    toReportingType(std::underlying_type_t<ReportingType> value)
+{
+    return toEnum<ReportingType, minEnumValue(convDataReportingType),
+                  maxEnumValue(convDataReportingType)>(value);
+}
+
+inline ReportingType toReportingType(const std::string& value)
+{
+    return toEnum(convDataReportingType, value);
+}
+
+inline std::string enumToString(ReportingType value)
+{
+    return std::string(enumToString(convDataReportingType, value));
+}
+
+} // namespace utils
diff --git a/src/types/trigger_types.hpp b/src/types/trigger_types.hpp
index a2a2e82..0ad9087 100644
--- a/src/types/trigger_types.hpp
+++ b/src/types/trigger_types.hpp
@@ -26,9 +26,9 @@
         std::make_pair("UpdateReport", TriggerAction::UpdateReport)};
 }
 
-inline TriggerAction stringToTriggerAction(const std::string& str)
+inline TriggerAction toTriggerAction(const std::string& str)
 {
-    return utils::stringToEnum(details::convDataTriggerAction, str);
+    return utils::toEnum(details::convDataTriggerAction, str);
 }
 
 namespace discrete
@@ -50,9 +50,9 @@
 
 } // namespace details
 
-inline Severity stringToSeverity(const std::string& str)
+inline Severity toSeverity(const std::string& str)
 {
-    return utils::stringToEnum(details::convDataSeverity, str);
+    return utils::toEnum(details::convDataSeverity, str);
 }
 
 inline std::string severityToString(Severity v)
@@ -103,9 +103,9 @@
 
 } // namespace details
 
-inline Type stringToType(const std::string& str)
+inline Type toType(const std::string& str)
 {
-    return utils::stringToEnum(details::convDataType, str);
+    return utils::toEnum(details::convDataType, str);
 }
 
 inline std::string typeToString(Type v)
@@ -113,9 +113,9 @@
     return std::string(utils::enumToString(details::convDataType, v));
 }
 
-inline Direction stringToDirection(const std::string& str)
+inline Direction toDirection(const std::string& str)
 {
-    return utils::stringToEnum(details::convDataDirection, str);
+    return utils::toEnum(details::convDataDirection, str);
 }
 
 inline std::string directionToString(Direction v)