1/*
2 * Copyright (c) 2021 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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_HELPER_H
17#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_HELPER_H
18
19#include <vector>
20
21#include "notification_slot.h"
22#include "reminder_request.h"
23
24namespace OHOS {
25namespace Notification {
26class ReminderHelper {
27public:
28    /**
29     * Publishes a scheduled reminder.
30     *
31     * Third-party applications can call this method to publish a scheduled reminder. After this method is called,
32     * the timing and pop-up notification functions of the calling application will be performed by the system service
33     * agent in the background, even when the application is frozen or exits. You can call the
34     * ReminderRequest::SetWantAgentInfo(WantAgentInfo wantAgentInfo) method to specify whether to start the
35     * application after the pop-up notification is taped.
36     *
37     * The background agent maintains an ordered list of reminders for all third-party applications. The list is
38     * updated based on the scheduled trigger time of each reminder. The system starts only one most recent scheduled
39     * reminder at a time. If a reminder with a more recent trigger time is added, the new scheduled reminder will
40     * be put on top of the list. The next reminder is triggered only after the current reminder is complete.
41     *
42     * @note One application can create a maximum of 30 valid reminders, and the total number of valid reminders
43     * in the system cannot exceed 2000. The minimum snooze interval for a reminder is 5 minutes.
44     *
45     * @param reminder Indicates the reminder instance to publish. This parameter cannot be null. Otherwise,
46     *                 an exception will be thrown due to invalid parameters, causing the application to crash.
47     * @return Returns publish reminder result.
48     *                 Reminder id will be set with a number >= 0 if publishing the reminder successfully, Otherwise
49     *                 reminder id is -1. You can call reminder.GetReminderId() to get the reminder id.
50     */
51    static ErrCode PublishReminder(ReminderRequest &reminder);
52
53    /**
54     * Cancels a specified reminder.
55     *
56     * @param reminderId Indicates the ID of the reminder instance to cancel.
57     * @return Returns cancel reminder result.
58     */
59    static ErrCode CancelReminder(const int32_t reminderId);
60
61    /**
62     * Cancels all reminders of current third part application.
63     *
64     * @return Returns cancel all reminders result.
65     */
66    static ErrCode CancelAllReminders();
67
68    /**
69     * Obtains all valid reminder notifications set by the current application, namely, the reminders that will
70     * still be triggered later. If a reminder will never be triggered again, it is not considered a valid reminder.
71     *
72     * @param[out] validReminders Indicates an initial vector to receive the result.
73     * @return Returns an array list containing all valid reminder notifications set by the current application.
74     */
75    static ErrCode GetValidReminders(std::vector<sptr<ReminderRequest>> &validReminders);
76
77    /**
78     * Creates a NotificationSlot.
79     *
80     * After a notification slot is created by using this method, only the name and description of the notification
81     * slot can be changed. Changes to the other attributes, such as the vibration status and notification tone,
82     * will no longer take effect.
83     *
84     * You can call the ReminderRequest#setSlotId(String) method to bind the slot for publishing a reminder.
85     * When the application is uninstalled, all notification slots related to the application will be deleted.
86     *
87     * @param slot Indicates the NotificationSlot instance to add.
88     * @return Returns add notification slot result.
89     */
90    static ErrCode AddNotificationSlot(const NotificationSlot &slot);
91
92    /**
93     * Removes a NotificationSlot instance used by the reminder.
94     *
95     * @param slotType Indicates the type of the slot, which is set when calling AddNotificationSlot to add a slot.
96     * @return Returns remove notification slot result.
97     */
98    static ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType);
99
100    /**
101     * @brief Add exclude date for reminder
102     *
103     * @param reminderId Identifies the reminders id.
104     * @param date exclude date
105     * @return Returns ERR_OK on success, others on failure.
106     */
107    static ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date);
108
109    /**
110     * @brief Clear exclude date for reminder
111     *
112     * @param reminderId Identifies the reminders id.
113     * @return Returns ERR_OK on success, others on failure.
114     */
115    static ErrCode DelExcludeDates(const int32_t reminderId);
116
117    /**
118     * @brief Get exclude date for reminder
119     *
120     * @param reminderId Identifies the reminders id.
121     * @param dates exclude dates
122     * @return Returns ERR_OK on success, others on failure.
123     */
124    static ErrCode GetExcludeDates(const int32_t reminderId, std::vector<uint64_t>& dates);
125
126private:
127    static bool CheckPermission();
128};
129}  // namespace Reminder
130}  // namespace OHOS
131
132#endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_HELPER_H