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