1// Copyright (C) 2020 Storj Labs, Inc.
2// See LICENSE for copying information.
3
4/**
5 * Exposes all notifications-related functionality.
6 */
7export interface NotificationsApi {
8    /**
9     * Fetches notifications.
10     * @throws Error
11     */
12    get(cursor: NotificationsCursor): Promise<NotificationsResponse>;
13
14    /**
15     * Marks single notification as read.
16     * @throws Error
17     */
18    read(id: string): Promise<void>;
19
20    /**
21     * Marks all notification as read.
22     * @throws Error
23     */
24    readAll(): Promise<void>;
25}
26
27/**
28 * Describes notification entity.
29 */
30export class Notification {
31    public constructor(
32        public id: string = '',
33        public senderId: string = '',
34        public type: NotificationTypes = NotificationTypes.Custom,
35        public title: string = '',
36        public message: string = '',
37        public readAt: Date | null = null,
38        public createdAt: Date = new Date(),
39    ) {}
40}
41
42/**
43 * Describes all current notifications types.
44 */
45export enum NotificationTypes {
46    Custom = 0,
47    AuditCheckFailure = 1,
48    Disqualification = 2,
49    Suspension = 3,
50}
51
52/**
53 * Describes page offset for pagination.
54 */
55export class NotificationsCursor {
56    private DEFAULT_LIMIT = 7;
57
58    public constructor(
59        public page: number = 0,
60        public limit: number = 0,
61    ) {
62        if (!this.limit) {
63            this.limit = this.DEFAULT_LIMIT;
64        }
65    }
66}
67
68/**
69 * Describes response object from server.
70 */
71export class NotificationsResponse {
72    public constructor(
73        public page: NotificationsPage = new NotificationsPage(),
74        public unreadCount: number = 0,
75        public totalCount: number = 0,
76    ) {}
77}
78
79/**
80 * Describes page related notification information.
81 */
82export class NotificationsPage {
83    public constructor(
84        public notifications: Notification[] = [],
85        public pageCount: number = 0,
86    ) {}
87}
88