|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace TK\API\ValueObject; |
|
5
|
|
|
|
|
6
|
|
|
use DateTimeImmutable; |
|
7
|
|
|
use TK\API\Exception\InvalidArgumentException; |
|
8
|
|
|
|
|
9
|
|
|
final class GetTimetableParameters implements ValueObjectInterface |
|
10
|
|
|
{ |
|
11
|
|
|
public const TRIP_TYPE_ROUND_TRIP = 'R'; |
|
12
|
|
|
public const TRIP_TYPE_ONE_WAY = 'O'; |
|
13
|
|
|
public const SCHEDULE_TYPE_WEEKLY = 'W'; |
|
14
|
|
|
public const SCHEDULE_TYPE_MONTHLY = 'M'; |
|
15
|
|
|
public const SCHEDULE_TYPE_DAILY = 'D'; |
|
16
|
|
|
|
|
17
|
|
|
private static $tripTypeEnum = ['O', 'R']; |
|
18
|
|
|
private static $scheduleTypeEnum = ['D', 'M', 'W']; |
|
19
|
|
|
|
|
20
|
|
|
private $queryParameters; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
AirScheduleRQ $airScheduleRQ, |
|
24
|
|
|
string $scheduleType, |
|
25
|
|
|
string $tripType |
|
26
|
|
|
) { |
|
27
|
|
|
$this->queryParameters['OTA_AirScheduleRQ'] = $airScheduleRQ->getValue(); |
|
28
|
|
|
$this->setScheduleType($scheduleType); |
|
29
|
|
|
$this->setTripType($tripType); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function withReturnDate(?DateTimeImmutable $returnDate) : GetTimetableParameters |
|
33
|
|
|
{ |
|
34
|
|
|
$this->setReturnDate($returnDate); |
|
35
|
|
|
return $this; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
private function setTripType(string $tripType) : void |
|
39
|
|
|
{ |
|
40
|
|
|
if (!\in_array($tripType, self::$tripTypeEnum, true)) { |
|
41
|
|
|
throw new InvalidArgumentException( |
|
42
|
|
|
'Invalid Trip Type. Possible values are "' . |
|
43
|
|
|
implode(', ', self::$tripTypeEnum) . '"' . |
|
44
|
|
|
' but provided value is "' . $tripType . '"' |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
$this->queryParameters['tripType'] = $tripType; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function setReturnDate(?DateTimeImmutable $returnDate) : void |
|
51
|
|
|
{ |
|
52
|
|
|
if ($returnDate !== null) { |
|
53
|
|
|
$this->queryParameters['returnDate'] = $returnDate->format('Y-m-d'); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function setScheduleType(string $scheduleType) : void |
|
58
|
|
|
{ |
|
59
|
|
|
if (!\in_array($scheduleType, self::$scheduleTypeEnum, true)) { |
|
60
|
|
|
throw new InvalidArgumentException( |
|
61
|
|
|
'Invalid Trip Type. Possible values are "' . |
|
62
|
|
|
implode(', ', self::$scheduleTypeEnum) . '"' . |
|
63
|
|
|
' but provided value is "' . $scheduleType . '"' |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
$this->queryParameters['scheduleType'] = $scheduleType; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getValue() : array |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->queryParameters; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|