|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Kerox\Messenger\Model\Message\Attachment\Template; |
|
6
|
|
|
|
|
7
|
|
|
use Kerox\Messenger\Model\Message\Attachment\Template; |
|
8
|
|
|
use Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightInfo; |
|
9
|
|
|
|
|
10
|
|
|
class AirlineUpdateTemplate extends AbstractAirlineTemplate |
|
11
|
|
|
{ |
|
12
|
|
|
public const UPDATE_TYPE_DELAY = 'delay'; |
|
13
|
|
|
public const UPDATE_TYPE_GATE_CHANGE = 'gate_change'; |
|
14
|
|
|
public const UPDATE_TYPE_CANCELLATION = 'cancellation'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var null|string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $introMessage; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $updateType; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $pnrNumber; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var \Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightInfo |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $updateFlightInfo; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* AirlineUpdate constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $updateType |
|
40
|
|
|
* @param string $locale |
|
41
|
|
|
* @param string $pnrNumber |
|
42
|
|
|
* @param \Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightInfo $updateFlightInfo |
|
43
|
|
|
* |
|
44
|
|
|
* @throws \InvalidArgumentException |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(string $updateType, string $locale, string $pnrNumber, FlightInfo $updateFlightInfo) |
|
47
|
|
|
{ |
|
48
|
|
|
parent::__construct($locale); |
|
49
|
|
|
|
|
50
|
|
|
$this->isValidUpdateType($updateType); |
|
51
|
|
|
|
|
52
|
|
|
$this->updateType = $updateType; |
|
53
|
|
|
$this->pnrNumber = $pnrNumber; |
|
54
|
|
|
$this->updateFlightInfo = $updateFlightInfo; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param string $updateType |
|
59
|
|
|
* @param string $locale |
|
60
|
|
|
* @param string $pnrNumber |
|
61
|
|
|
* @param \Kerox\Messenger\Model\Message\Attachment\Template\Airline\FlightInfo $updateFlightInfo |
|
62
|
|
|
* |
|
63
|
|
|
* @throws \InvalidArgumentException |
|
64
|
|
|
* |
|
65
|
|
|
* @return \Kerox\Messenger\Model\Message\Attachment\Template\AirlineUpdateTemplate |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function create( |
|
68
|
|
|
string $updateType, |
|
69
|
|
|
string $locale, |
|
70
|
|
|
string $pnrNumber, |
|
71
|
|
|
FlightInfo $updateFlightInfo |
|
72
|
|
|
): self { |
|
73
|
|
|
return new self($updateType, $locale, $pnrNumber, $updateFlightInfo); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param string $introMessage |
|
78
|
|
|
* |
|
79
|
|
|
* @return \Kerox\Messenger\Model\Message\Attachment\Template\AirlineUpdateTemplate |
|
80
|
|
|
*/ |
|
81
|
|
|
public function setIntroMessage($introMessage): self |
|
82
|
|
|
{ |
|
83
|
|
|
$this->introMessage = $introMessage; |
|
84
|
|
|
|
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param string $updateType |
|
90
|
|
|
* |
|
91
|
|
|
* @throws \InvalidArgumentException |
|
92
|
|
|
*/ |
|
93
|
|
|
private function isValidUpdateType(string $updateType): void |
|
94
|
|
|
{ |
|
95
|
|
|
$allowedUpdateType = $this->getAllowedUpdateType(); |
|
96
|
|
|
if (!\in_array($updateType, $allowedUpdateType, true)) { |
|
97
|
|
|
throw new \InvalidArgumentException('$updateType must be either ' . implode(', ', $allowedUpdateType)); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return array |
|
103
|
|
|
*/ |
|
104
|
|
|
private function getAllowedUpdateType(): array |
|
105
|
|
|
{ |
|
106
|
|
|
return [ |
|
107
|
|
|
self::UPDATE_TYPE_DELAY, |
|
108
|
|
|
self::UPDATE_TYPE_GATE_CHANGE, |
|
109
|
|
|
self::UPDATE_TYPE_CANCELLATION, |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return array |
|
115
|
|
|
*/ |
|
116
|
|
|
public function toArray(): array |
|
117
|
|
|
{ |
|
118
|
|
|
$array = parent::toArray(); |
|
119
|
|
|
$array += [ |
|
120
|
|
|
'payload' => [ |
|
121
|
|
|
'template_type' => Template::TYPE_AIRLINE_UPDATE, |
|
122
|
|
|
'intro_message' => $this->introMessage, |
|
123
|
|
|
'update_type' => $this->updateType, |
|
124
|
|
|
'locale' => $this->locale, |
|
125
|
|
|
'pnr_number' => $this->pnrNumber, |
|
126
|
|
|
'update_flight_info' => $this->updateFlightInfo, |
|
127
|
|
|
], |
|
128
|
|
|
]; |
|
129
|
|
|
|
|
130
|
|
|
return $this->arrayFilter($array); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|