Correction to default value in avro message
[aquarium] / src / main / avro / aquarium-user-state.avdl
index 8f37930..d05a8f2 100644 (file)
@@ -41,67 +41,94 @@ protocol AquariumUserState {
 
   record UserAgreementMsg {
     string id;
-    union {string, null} relatedIMEventID;
+    union {string, null} relatedIMEventOriginalID;
+    string userID;
+    long occurredMillis = 0; // when was this agreement created inside Aquarium
     long @order("ascending") validFromMillis;
     long validToMillis;
     string role;
     union {FullPriceTableMsg, null} fullPriceTableRef; // If null, then get from aquarium policy
+    union {IMEventMsg, null} relatedIMEventMsg; // non-null if there is a related IMEvent
   }
 
-  record WorkingResourceInstanceChargingStateMsg {
+  record ResourceInstanceChargingStateMsg {
+    string clientID; // who sent me?
+    string resource; // what kind of resource am I?
+    string instanceID; // who am I?
     map<AnyValueMsg> details;
     array<ResourceEventMsg> previousEvents;
     array<ResourceEventMsg> implicitlyIssuedStartEvents;
-    double accumulatingAmount;
-    double oldAccumulatingAmount;
-    double previousValue;
-    double currentValue;
+   string accumulatingAmount;
+   string oldAccumulatingAmount;
+   string previousValue;
+   string currentValue;
   }
 
-  record WorkingResourcesChargingStateMsg {
+  record ResourcesChargingStateMsg {
+    string resource; // who am I?
     map<AnyValueMsg> details;
-    map<WorkingResourceInstanceChargingStateMsg> stateOfResourceInstance;
+    map<ResourceInstanceChargingStateMsg> stateOfResourceInstance;
   }
 
-  record WorkingAgreementHistoryMsg {
+  record UserAgreementHistoryMsg {
+    string originalID;
+    union {string, null} inStoreID;
+    string userID;
+    long latestOccurredMillis; // the latest occurredMillis of all underlying agreements
+    long latestValidFromMillis; // the latest validFromMillis of all underlying agreements
+    long userCreationTimeMillis = 0;
     array<UserAgreementMsg> agreements;
   }
 
   record ChargeslotMsg {
     long startMillis;
     long stopMillis;
-    double unitPrice;
+   string unitPrice;
     string explanation = "";
-    double creditsToSubtract;
+   string creditsToSubtract = 0.0;
   }
 
+  // The following equation must hold (within a very small error):
+  //   `newTotalCredits = oldTotalCredits - sumOfCreditsToSubtract`.
   record WalletEntryMsg {
-    string userID;
-    double sumOfCreditsToSubtract;
-    double oldTotalCredits;
-    double newTotalCredits;
-    long whenComputedMillis;
+    string userID; // The user ID this wallet entry is related to.
+    string sumOfCreditsToSubtract; // The credit amount generated for this wallet entry.
+    string oldTotalCredits;
+    string newTotalCredits;
+    long whenComputedMillis; // When the computation took place
     long referenceStartMillis;
     long referenceStopMillis;
     int billingYear;
     int billingMonth;
-    int billingDay;
-    array<ChargeslotMsg> chargeslots;
+    int billingMonthDay;
+    array<ChargeslotMsg> chargeslots; // The details of the credit computation
     array<ResourceEventMsg> resourceEvents; // current is the last one
     ResourceTypeMsg resourceType;
     boolean isSynthetic = false;
   }
 
-  record WorkingUserStateMsg {
+  // convenient wrapper for a list of wallet entries
+  record WalletEntriesMsg {
+    array<WalletEntryMsg> entries;
+  }
+
+  record UserStateMsg {
+    string originalID; // internal Aquarium ID
+    union {string, null} inStoreID; // From Aquarium store
     string userID;
-    union {string, null} parentUserStateIDInStore;
-    map<ResourceTypeMsg> resourceTypesMap;
-    map<WorkingResourcesChargingStateMsg> workingStateOfResources;
-    double totalCredits;
-    WorkingAgreementHistoryMsg workingAgreementHistory;
-    long latestUpdateMillis;
+    long occurredMillis; // When we created the event
+    union {string, null} parentOriginalID;
+    union {string, null} parentInStoreID;
+    boolean isFirst = false; // True only for the very first user state
+    map<ResourcesChargingStateMsg> stateOfResources; // Map[ResourceTypeMsg.name.type, ]
+    string totalCredits = "0";
+    long latestUpdateMillis; // // last update of this working user state
     long latestResourceEventOccurredMillis;
-    long billingPeriodOutOfSyncResourceEventsCounter;
+    long billingPeriodOutOfSyncResourceEventsCounter = 0;
+    int billingYear;
+    int billingMonth;
+    int billingMonthDay;
+    boolean isFullBillingMonth = false;
     array<WalletEntryMsg> walletEntries;
   }
 }
\ No newline at end of file