Correction to default value in avro message
[aquarium] / src / main / avro / aquarium-user-state.avdl
index c5e8394..d05a8f2 100644 (file)
@@ -39,69 +39,96 @@ protocol AquariumUserState {
   import idl "aquarium-anyvalue.avdl";
   import idl "aquarium-events.avdl";
 
-  record _UserAgreement {
+  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 {_FullPriceTable, null} fullPriceTableRef; // If null, then get from aquarium policy
+    union {FullPriceTableMsg, null} fullPriceTableRef; // If null, then get from aquarium policy
+    union {IMEventMsg, null} relatedIMEventMsg; // non-null if there is a related IMEvent
   }
 
-  record _WorkingResourceInstanceChargingState {
-    map<_AnyValue> details;
-    array<_ResourceEvent> previousEvents;
-    array<_ResourceEvent> implicitlyIssuedStartEvents;
-    double accumulatingAmount;
-    double oldAccumulatingAmount;
-    double previousValue;
-    double currentValue;
+  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;
+   string accumulatingAmount;
+   string oldAccumulatingAmount;
+   string previousValue;
+   string currentValue;
   }
 
-  record _WorkingResourcesChargingState {
-    map<_AnyValue> details;
-    map<_WorkingResourceInstanceChargingState> stateOfResourceInstance;
+  record ResourcesChargingStateMsg {
+    string resource; // who am I?
+    map<AnyValueMsg> details;
+    map<ResourceInstanceChargingStateMsg> stateOfResourceInstance;
   }
 
-  record _WorkingAgreementHistory {
-    array<_UserAgreement> agreements;
+  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 _Chargeslot {
+  record ChargeslotMsg {
     long startMillis;
     long stopMillis;
-    double unitPrice;
+   string unitPrice;
     string explanation = "";
-    double creditsToSubtract;
+   string creditsToSubtract = 0.0;
   }
 
-  record _WalletEntry {
-    string userID;
-    double sumOfCreditsToSubtract;
-    double oldTotalCredits;
-    double newTotalCredits;
-    long whenComputedMillis;
+  // The following equation must hold (within a very small error):
+  //   `newTotalCredits = oldTotalCredits - sumOfCreditsToSubtract`.
+  record WalletEntryMsg {
+    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<_Chargeslot> chargeslots;
-    array<_ResourceEvent> resourceEvents; // current is the last one
-    _ResourceType resourceType;
+    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 _WorkingUserState {
+  // 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<_ResourceType> resourceTypesMap;
-    map<_WorkingResourcesChargingState> workingStateOfResources;
-    double totalCredits;
-    _WorkingAgreementHistory 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;
-    array<_WalletEntry> walletEntries;
+    long billingPeriodOutOfSyncResourceEventsCounter = 0;
+    int billingYear;
+    int billingMonth;
+    int billingMonthDay;
+    boolean isFullBillingMonth = false;
+    array<WalletEntryMsg> walletEntries;
   }
 }
\ No newline at end of file