1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SUBSCRIPTION_H
17 #define OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SUBSCRIPTION_H
18 #include "serializable/serializable.h"
19 namespace OHOS::DistributedData {
20 struct API_EXPORT Subscription final : public Serializable {
21     int32_t userId = 0;
22     std::string id;
23     std::map<std::string, uint64_t> expiresTime;
24 
25     struct API_EXPORT Relation final : public Serializable {
26         std::string id;
27         std::string bundleName;
28         std::map<std::string, std::string> relations;
29         bool Marshal(json &node) const override;
30         bool Unmarshal(const json &node) override;
31     };
32 
33     bool Marshal(json &node) const;
34     bool Unmarshal(const json &node);
35     std::string GetKey();
36     std::string GetRelationKey(const std::string &bundleName);
37     uint64_t GetMinExpireTime() const;
38     static std::string GetKey(int32_t userId);
39     static std::string GetRelationKey(int32_t userId, const std::string &bundleName);
40     static std::string GetPrefix(const std::initializer_list<std::string> &fields);
41 private:
42     static constexpr const char *PREFIX = "CLOUD_SUBSCRIPTION";
43     static constexpr const char *RELATION_PREFIX = "CLOUD_RELATION";
44     static constexpr uint64_t INVALID_TIME = 0;
45 };
46 } // namespace OHOS::DistributedData
47 #endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CLOUD_SUBSCRIPTION_H
48