1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VasilDakov\Speedy\Service\Shipment; |
6
|
|
|
|
7
|
|
|
use DateTime; |
8
|
|
|
use VasilDakov\Speedy\Speedy; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ShipmentService |
12
|
|
|
* |
13
|
|
|
* @author Valentin Valkanov <[email protected]> |
14
|
|
|
* @author Vasil Dakov <[email protected]> |
15
|
|
|
* @copyright |
16
|
|
|
* @version |
17
|
|
|
*/ |
18
|
|
|
class ShipmentService |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var DateTime|null |
22
|
|
|
*/ |
23
|
|
|
private ?DateTime $pickupDate = null; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var bool |
27
|
|
|
*/ |
28
|
|
|
private bool $autoAdjustPickupDate = false; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
private int $serviceId; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var ShipmentAdditionalServices|null |
37
|
|
|
*/ |
38
|
|
|
private ?ShipmentAdditionalServices $additionalServices = null; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var int|null |
42
|
|
|
*/ |
43
|
|
|
private ?int $deferredDays = null; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
private bool $saturdayDelivery = false; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param int $serviceId |
52
|
|
|
*/ |
53
|
2 |
|
public function __construct(int $serviceId) |
54
|
|
|
{ |
55
|
2 |
|
$this->serviceId = $serviceId; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return DateTime|null |
60
|
|
|
*/ |
61
|
1 |
|
public function getPickupDate(): ?DateTime |
62
|
|
|
{ |
63
|
1 |
|
return $this->pickupDate; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param DateTime $pickupDate |
68
|
|
|
* @return ShipmentService |
69
|
|
|
*/ |
70
|
1 |
|
public function setPickupDate(DateTime $pickupDate): self |
71
|
|
|
{ |
72
|
1 |
|
$this->pickupDate = $pickupDate; |
73
|
|
|
|
74
|
1 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
3 |
|
public function isAutoAdjustPickupDate(): bool |
81
|
|
|
{ |
82
|
3 |
|
return $this->autoAdjustPickupDate; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param bool $autoAdjustPickupDate |
87
|
|
|
* @return ShipmentService |
88
|
|
|
*/ |
89
|
1 |
|
public function setAutoAdjustPickupDate(bool $autoAdjustPickupDate): self |
90
|
|
|
{ |
91
|
1 |
|
$this->autoAdjustPickupDate = $autoAdjustPickupDate; |
92
|
|
|
|
93
|
1 |
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return int|null |
98
|
|
|
*/ |
99
|
4 |
|
public function getServiceId(): ?int |
100
|
|
|
{ |
101
|
4 |
|
return $this->serviceId; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param int $serviceId |
106
|
|
|
*/ |
107
|
|
|
public function setServiceId(int $serviceId): void |
108
|
|
|
{ |
109
|
|
|
$this->serviceId = $serviceId; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return ShipmentAdditionalServices|null |
114
|
|
|
*/ |
115
|
2 |
|
public function getAdditionalServices(): ?ShipmentAdditionalServices |
116
|
|
|
{ |
117
|
2 |
|
return $this->additionalServices; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param ShipmentAdditionalServices $additionalServices |
122
|
|
|
* @return ShipmentService |
123
|
|
|
*/ |
124
|
1 |
|
public function setAdditionalServices(ShipmentAdditionalServices $additionalServices): self |
125
|
|
|
{ |
126
|
1 |
|
$this->additionalServices = $additionalServices; |
127
|
|
|
|
128
|
1 |
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return int|null |
133
|
|
|
*/ |
134
|
1 |
|
public function getDeferredDays(): ?int |
135
|
|
|
{ |
136
|
1 |
|
return $this->deferredDays; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param int $deferredDays |
141
|
|
|
* @return ShipmentService |
142
|
|
|
*/ |
143
|
1 |
|
public function setDeferredDays(int $deferredDays): self |
144
|
|
|
{ |
145
|
1 |
|
$this->deferredDays = $deferredDays; |
146
|
|
|
|
147
|
1 |
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return bool |
152
|
|
|
*/ |
153
|
3 |
|
public function isSaturdayDelivery(): bool |
154
|
|
|
{ |
155
|
3 |
|
return $this->saturdayDelivery; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param bool $saturdayDelivery |
160
|
|
|
* @return ShipmentService |
161
|
|
|
*/ |
162
|
1 |
|
public function setSaturdayDelivery(bool $saturdayDelivery): self |
163
|
|
|
{ |
164
|
1 |
|
$this->saturdayDelivery = $saturdayDelivery; |
165
|
|
|
|
166
|
1 |
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return array |
172
|
|
|
*/ |
173
|
3 |
|
public function toArray(): array |
174
|
|
|
{ |
175
|
3 |
|
$data = [ |
176
|
3 |
|
Speedy::SERVICE_ID => $this->getServiceId(), |
177
|
3 |
|
Speedy::AUTO_ADJUST_PICKUP_DATE => $this->isAutoAdjustPickupDate(), |
178
|
3 |
|
Speedy::SATURDAY_DELIVERY => $this->isSaturdayDelivery() |
179
|
3 |
|
]; |
180
|
|
|
|
181
|
3 |
|
if (null !== $this->pickupDate) { |
182
|
1 |
|
$data[Speedy::PICKUP_DATE] = $this->getPickupDate(); |
183
|
|
|
} |
184
|
|
|
|
185
|
3 |
|
if (null !== $this->additionalServices) { |
186
|
2 |
|
$data[Speedy::ADDITIONAL_SERVICES] = $this->getAdditionalServices(); |
187
|
|
|
} |
188
|
|
|
|
189
|
3 |
|
if (null !== $this->deferredDays) { |
190
|
1 |
|
$data[Speedy::DEFERRED_DAYS] = $this->getDeferredDays(); |
191
|
|
|
} |
192
|
|
|
|
193
|
3 |
|
return $data; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|