-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMessage.php
More file actions
160 lines (143 loc) · 3.87 KB
/
Message.php
File metadata and controls
160 lines (143 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
namespace Utopia\Migration\Resources\Messaging;
use Utopia\Migration\Resource;
use Utopia\Migration\Transfer;
class Message extends Resource
{
/**
* @param string $id
* @param string $providerType
* @param array<string> $topics
* @param array<string> $users
* @param array<string> $targets
* @param array<string, mixed> $data
* @param string $messageStatus
* @param string $scheduledAt
* @param string $deliveredAt
* @param array<string> $deliveryErrors
* @param int $deliveredTotal
*/
public function __construct(
string $id,
private readonly string $providerType,
private readonly array $topics = [],
private readonly array $users = [],
private readonly array $targets = [],
private readonly array $data = [],
private readonly string $messageStatus = '',
private readonly string $scheduledAt = '',
private readonly string $deliveredAt = '',
private readonly array $deliveryErrors = [],
private readonly int $deliveredTotal = 0,
protected string $createdAt = '',
protected string $updatedAt = '',
) {
$this->id = $id;
}
/**
* @param array<string, mixed> $array
* @return self
*/
public static function fromArray(array $array): self
{
return new self(
$array['id'],
$array['providerType'] ?? '',
$array['topics'] ?? [],
$array['users'] ?? [],
$array['targets'] ?? [],
$array['data'] ?? [],
$array['messageStatus'] ?? $array['status'] ?? '',
$array['scheduledAt'] ?? '',
$array['deliveredAt'] ?? '',
$array['deliveryErrors'] ?? [],
$array['deliveredTotal'] ?? 0,
$array['createdAt'] ?? '',
$array['updatedAt'] ?? '',
);
}
/**
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'providerType' => $this->providerType,
'topics' => $this->topics,
'users' => $this->users,
'targets' => $this->targets,
'data' => $this->data,
'messageStatus' => $this->messageStatus,
'scheduledAt' => $this->scheduledAt,
'deliveredAt' => $this->deliveredAt,
'deliveryErrors' => $this->deliveryErrors,
'deliveredTotal' => $this->deliveredTotal,
'createdAt' => $this->createdAt,
'updatedAt' => $this->updatedAt,
];
}
public static function getName(): string
{
return Resource::TYPE_MESSAGE;
}
public function getGroup(): string
{
return Transfer::GROUP_MESSAGING;
}
public function getProviderType(): string
{
return $this->providerType;
}
/**
* @return array<string>
*/
public function getTopics(): array
{
return $this->topics;
}
/**
* @return array<string>
*/
public function getUsers(): array
{
return $this->users;
}
/**
* @return array<string>
*/
public function getTargets(): array
{
return $this->targets;
}
/**
* @return array<string, mixed>
*/
public function getData(): array
{
return $this->data;
}
public function getMessageStatus(): string
{
return $this->messageStatus;
}
public function getScheduledAt(): string
{
return $this->scheduledAt;
}
public function getDeliveredAt(): string
{
return $this->deliveredAt;
}
/**
* @return array<string>
*/
public function getDeliveryErrors(): array
{
return $this->deliveryErrors;
}
public function getDeliveredTotal(): int
{
return $this->deliveredTotal;
}
}