Move UserSubscription to composition

This allows for two very important simplifying changes.  First, we can
use the default copy operators on the UserSubscription class, which is
far less error prone than writing it manually, which we have two copies
of in code already.

Second, it allows the Subscription class to move to using values rather
than shared_ptr everywhere, which cleans up a significant amount of
code.

Tested:
Ran Redfish-Event-Listener, subscription created and destroyed
correctly.
Calling POST SubmitTestEvent showed events propagating to server.

Change-Id: I6d258cfe3594edddf3960ae2d4559d70acca1bf8
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/include/event_service_store.hpp b/include/event_service_store.hpp
index 9761eb5..f875986 100644
--- a/include/event_service_store.hpp
+++ b/include/event_service_store.hpp
@@ -12,6 +12,7 @@
 
 struct UserSubscription
 {
+    // Represents a Redfish EventDestination instance
     std::string id;
     boost::urls::url destinationUrl;
     std::string protocol;
@@ -27,11 +28,10 @@
     std::vector<std::string> metricReportDefinitions;
     std::vector<std::string> originResources;
 
-    static std::shared_ptr<UserSubscription> fromJson(
+    static std::optional<UserSubscription> fromJson(
         const nlohmann::json::object_t& j, const bool loadFromOldConfig = false)
     {
-        std::shared_ptr<UserSubscription> subvalue =
-            std::make_shared<UserSubscription>();
+        UserSubscription subvalue;
         for (const auto& element : j)
         {
             if (element.first == "Id")
@@ -42,7 +42,7 @@
                 {
                     continue;
                 }
-                subvalue->id = *value;
+                subvalue.id = *value;
             }
             else if (element.first == "Destination")
             {
@@ -58,7 +58,7 @@
                 {
                     continue;
                 }
-                subvalue->destinationUrl = std::move(*url);
+                subvalue.destinationUrl = std::move(*url);
             }
             else if (element.first == "Protocol")
             {
@@ -68,7 +68,7 @@
                 {
                     continue;
                 }
-                subvalue->protocol = *value;
+                subvalue.protocol = *value;
             }
             else if (element.first == "VerifyCertificate")
             {
@@ -77,7 +77,7 @@
                 {
                     continue;
                 }
-                subvalue->verifyCertificate = *value;
+                subvalue.verifyCertificate = *value;
             }
             else if (element.first == "DeliveryRetryPolicy")
             {
@@ -87,7 +87,7 @@
                 {
                     continue;
                 }
-                subvalue->retryPolicy = *value;
+                subvalue.retryPolicy = *value;
             }
             else if (element.first == "Context")
             {
@@ -97,7 +97,7 @@
                 {
                     continue;
                 }
-                subvalue->customText = *value;
+                subvalue.customText = *value;
             }
             else if (element.first == "EventFormatType")
             {
@@ -107,7 +107,7 @@
                 {
                     continue;
                 }
-                subvalue->eventFormatType = *value;
+                subvalue.eventFormatType = *value;
             }
             else if (element.first == "SubscriptionType")
             {
@@ -117,7 +117,7 @@
                 {
                     continue;
                 }
-                subvalue->subscriptionType = *value;
+                subvalue.subscriptionType = *value;
             }
             else if (element.first == "MessageIds")
             {
@@ -135,7 +135,7 @@
                     {
                         continue;
                     }
-                    subvalue->registryMsgIds.emplace_back(*value);
+                    subvalue.registryMsgIds.emplace_back(*value);
                 }
             }
             else if (element.first == "RegistryPrefixes")
@@ -154,7 +154,7 @@
                     {
                         continue;
                     }
-                    subvalue->registryPrefixes.emplace_back(*value);
+                    subvalue.registryPrefixes.emplace_back(*value);
                 }
             }
             else if (element.first == "ResourceTypes")
@@ -173,7 +173,7 @@
                     {
                         continue;
                     }
-                    subvalue->resourceTypes.emplace_back(*value);
+                    subvalue.resourceTypes.emplace_back(*value);
                 }
             }
             else if (element.first == "HttpHeaders")
@@ -194,7 +194,7 @@
                                          val.first);
                         continue;
                     }
-                    subvalue->httpHeaders.set(val.first, *value);
+                    subvalue.httpHeaders.set(val.first, *value);
                 }
             }
             else if (element.first == "MetricReportDefinitions")
@@ -213,7 +213,7 @@
                     {
                         continue;
                     }
-                    subvalue->metricReportDefinitions.emplace_back(*value);
+                    subvalue.metricReportDefinitions.emplace_back(*value);
                 }
             }
             else if (element.first == "OriginResources")
@@ -232,7 +232,7 @@
                     {
                         continue;
                     }
-                    subvalue->originResources.emplace_back(*value);
+                    subvalue.originResources.emplace_back(*value);
                 }
             }
             else
@@ -244,15 +244,14 @@
             }
         }
 
-        if ((subvalue->id.empty() && !loadFromOldConfig) ||
-            subvalue->destinationUrl.empty() || subvalue->protocol.empty() ||
-            subvalue->retryPolicy.empty() ||
-            subvalue->eventFormatType.empty() ||
-            subvalue->subscriptionType.empty())
+        if ((subvalue.id.empty() && !loadFromOldConfig) ||
+            subvalue.destinationUrl.empty() || subvalue.protocol.empty() ||
+            subvalue.retryPolicy.empty() || subvalue.eventFormatType.empty() ||
+            subvalue.subscriptionType.empty())
         {
             BMCWEB_LOG_ERROR("Subscription missing required field "
                              "information, refusing to restore");
-            return nullptr;
+            return std::nullopt;
         }
 
         return subvalue;
@@ -307,7 +306,7 @@
 class EventServiceStore
 {
   public:
-    boost::container::flat_map<std::string, std::shared_ptr<UserSubscription>>
+    boost::container::flat_map<std::string, UserSubscription>
         subscriptionsConfigMap;
     EventServiceConfig eventServiceConfig;