Completed
Push — master ( 9821e4...5b6eef )
by Tomáš
10:05 queued 10:05
created

Balikobot::getBranchesForLocation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 11
c 0
b 0
f 0
nc 2
nop 8
dl 0
loc 23
ccs 4
cts 4
cp 1
crap 2
rs 9.9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Services;
6
7
use Inspirum\Balikobot\Contracts\RequesterInterface;
8
use Inspirum\Balikobot\Definitions\Option;
9
use Inspirum\Balikobot\Definitions\Shipper;
10
use Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection;
11
use Inspirum\Balikobot\Model\Aggregates\PackageCollection;
12
use Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection;
13
use Inspirum\Balikobot\Model\Values\AdrUnit;
14
use Inspirum\Balikobot\Model\Values\Branch;
15
use Inspirum\Balikobot\Model\Values\Country;
16
use Inspirum\Balikobot\Model\Values\OrderedPackage;
17
use Inspirum\Balikobot\Model\Values\OrderedShipment;
18
use Inspirum\Balikobot\Model\Values\Package;
19
use Inspirum\Balikobot\Model\Values\PackageStatus;
20
use Inspirum\Balikobot\Model\Values\PackageTransportCost;
21
use Inspirum\Balikobot\Model\Values\PostCode;
22
use function array_keys;
23
use function count;
24
use function in_array;
25
26
class Balikobot
27
{
28
    /**
29
     * Balikobot API
30
     *
31
     * @var \Inspirum\Balikobot\Services\Client
32
     */
33
    private Client $client;
34
35
    /**
36
     * Balikobot constructor
37
     *
38
     * @param \Inspirum\Balikobot\Contracts\RequesterInterface $requester
39
     */
40 138
    public function __construct(RequesterInterface $requester)
41
    {
42 138
        $this->client = new Client($requester);
43
    }
44
45
    /**
46
     * All supported shipper services
47
     *
48
     * @return array<string>
49
     */
50 1
    public function getShippers(): array
51
    {
52 1
        return Shipper::all();
53
    }
54
55
    /**
56
     * Get list of active carriers
57
     *
58
     * @return array<string>
59
     *
60
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
61
     */
62 3
    public function getActiveShippers(): array
63
    {
64 3
        return $this->client->getActiveShippers();
65
    }
66
67
    /**
68
     * Add packages
69
     *
70
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
71
     *
72
     * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[]
73
     *
74
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
75
     */
76 11
    public function addPackages(PackageCollection $packages): OrderedPackageCollection
77
    {
78 11
        $labelsUrl = null;
79 11
        $response  = $this->client->addPackages($packages->getShipper(), $packages->toArray(), $labelsUrl);
80
81 10
        $orderedPackages = new OrderedPackageCollection();
82 10
        $orderedPackages->setLabelsUrl($labelsUrl);
83
84 10
        foreach ($response as $package) {
85 10
            $orderedPackages->add(OrderedPackage::newInstanceFromData($packages->getShipper(), $package));
86
        }
87
88 10
        return $orderedPackages;
89
    }
90
91
    /**
92
     * Exports order into Balikobot system
93
     *
94
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
95
     *
96
     * @return void
97
     *
98
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
99
     */
100 3
    public function dropPackages(OrderedPackageCollection $packages): void
101
    {
102 3
        $this->client->dropPackages($packages->getShipper(), $packages->getPackageIds());
103
    }
104
105
    /**
106
     * Exports order into Balikobot system
107
     *
108
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
109
     *
110
     * @return void
111
     *
112
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
113
     */
114 1
    public function dropPackage(OrderedPackage $package): void
115
    {
116 1
        $this->client->dropPackage($package->getShipper(), $package->getPackageId());
117
    }
118
119
    /**
120
     * Order shipment
121
     *
122
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
123
     *
124
     * @return \Inspirum\Balikobot\Model\Values\OrderedShipment
125
     *
126
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
127
     */
128 5
    public function orderShipment(OrderedPackageCollection $packages): OrderedShipment
129
    {
130 5
        $response = $this->client->orderShipment($packages->getShipper(), $packages->getPackageIds());
131
132 4
        return OrderedShipment::newInstanceFromData($packages->getShipper(), $packages->getPackageIds(), $response);
133
    }
134
135
    /**
136
     * Track package
137
     *
138
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
139
     *
140
     * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>
141
     *
142
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
143
     */
144 3
    public function trackPackage(OrderedPackage $package): array
145
    {
146 3
        $packages = new OrderedPackageCollection();
147 3
        $packages->add($package);
148
149 3
        return $this->trackPackages($packages)[0];
150
    }
151
152
    /**
153
     * Track packages
154
     *
155
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
156
     *
157
     * @return array<array<\Inspirum\Balikobot\Model\Values\PackageStatus>>
158
     *
159
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
160
     */
161 6
    public function trackPackages(OrderedPackageCollection $packages): array
162
    {
163 6
        $response = $this->client->trackPackages($packages->getShipper(), $packages->getCarrierIds());
164
165 5
        $statuses = [];
166
167 5
        foreach ($response as $responseStatuses) {
168 5
            $statuses[] = $this->createPackageStatusesCollection($responseStatuses);
169
        }
170
171 5
        return $statuses;
172
    }
173
174
    /**
175
     * Track package last status
176
     *
177
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
178
     *
179
     * @return \Inspirum\Balikobot\Model\Values\PackageStatus
180
     *
181
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
182
     */
183 2
    public function trackPackageLastStatus(OrderedPackage $package): PackageStatus
184
    {
185 2
        $packages = new OrderedPackageCollection();
186 2
        $packages->add($package);
187
188 2
        return $this->trackPackagesLastStatus($packages)[0];
189
    }
190
191
    /**
192
     * Track package last status
193
     *
194
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
195
     *
196
     * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>
197
     *
198
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
199
     */
200 5
    public function trackPackagesLastStatus(OrderedPackageCollection $packages): array
201
    {
202 5
        $response = $this->client->trackPackagesLastStatus($packages->getShipper(), $packages->getCarrierIds());
203
204 5
        return $this->createPackageStatusesCollection($response);
205
    }
206
207
    /**
208
     * Create package status collection for package
209
     *
210
     * @param array<array<string,float|string|null>> $response
211
     *
212
     * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>
213
     */
214 10
    private function createPackageStatusesCollection(array $response): array
215
    {
216 10
        $statuses = [];
217
218 10
        foreach ($response as $status) {
219 10
            $statuses[] = PackageStatus::newInstanceFromData($status);
220
        }
221
222 10
        return $statuses;
223
    }
224
225
    /**
226
     * Get overview for given shipper
227
     *
228
     * @param string $shipper
229
     *
230
     * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[]
231
     *
232
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
233
     */
234 3
    public function getOverview(string $shipper): OrderedPackageCollection
235
    {
236 3
        $response = $this->client->getOverview($shipper);
237
238 3
        $response = $response['packages'];
239
240 3
        $orderedPackages = new OrderedPackageCollection();
241
242 3
        foreach ($response as $package) {
243 2
            $orderedPackage = OrderedPackage::newInstanceFromData($shipper, $package);
244 2
            $orderedPackages->add($orderedPackage);
245
        }
246
247 3
        return $orderedPackages;
248
    }
249
250
    /**
251
     * Get labels for orders
252
     *
253
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
254
     *
255
     * @return string
256
     *
257
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
258
     */
259 4
    public function getLabels(OrderedPackageCollection $packages): string
260
    {
261 4
        return $this->client->getLabels($packages->getShipper(), $packages->getPackageIds());
262
    }
263
264
    /**
265
     * Gets complete information about a package
266
     *
267
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
268
     *
269
     * @return \Inspirum\Balikobot\Model\Values\Package
270
     *
271
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
272
     */
273 4
    public function getPackageInfo(OrderedPackage $package): Package
274
    {
275 4
        $response = $this->client->getPackageInfoByCarrierId($package->getShipper(), $package->getCarrierId());
276
277
        unset(
278 3
            $response['package_id'],
279 3
            $response['eshop_id'],
280 3
            $response['carrier_id'],
281 3
            $response['track_url'],
282 3
            $response['label_url'],
283 3
            $response['carrier_id_swap'],
284 3
            $response['pieces']
285
        );
286
287 3
        $options              = $response;
288 3
        $options[Option::EID] = $package->getBatchId();
289
290 3
        return new Package($options);
291
    }
292
293
    /**
294
     * Gets complete information about a package
295
     *
296
     * @param string $shipper
297
     * @param string $orderId
298
     *
299
     * @return \Inspirum\Balikobot\Model\Values\OrderedShipment
300
     *
301
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
302
     */
303 4
    public function getOrder(string $shipper, string $orderId): OrderedShipment
304
    {
305 4
        $response = $this->client->getOrder($shipper, $orderId);
306
307 3
        return OrderedShipment::newInstanceFromData($shipper, $response['package_ids'], $response);
308
    }
309
310
    /**
311
     * Returns available services for the given shipper
312
     *
313
     * @param string $shipper
314
     *
315
     * @return array<string,string>
316
     *
317
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
318
     */
319 6
    public function getServices(string $shipper): array
320
    {
321 6
        return $this->client->getServices($shipper);
322
    }
323
324
    /**
325
     * Returns available B2A services for the given shipper
326
     *
327
     * @param string $shipper
328
     *
329
     * @return array<string,string>
330
     *
331
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
332
     */
333 3
    public function getB2AServices(string $shipper): array
334
    {
335 3
        return $this->client->getB2AServices($shipper);
336
    }
337
338
    /**
339
     * Returns all manipulation units for the given shipper
340
     *
341
     * @param string $shipper
342
     * @param bool   $fullData
343
     *
344
     * @return array<string|array<mixed,mixed>>
345
     *
346
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
347
     */
348 5
    public function getManipulationUnits(string $shipper, bool $fullData = false): array
349
    {
350 5
        return $this->client->getManipulationUnits($shipper, $fullData);
351
    }
352
353
    /**
354
     * Returns available manipulation units for the given shipper
355
     *
356
     * @param string $shipper
357
     * @param bool   $fullData
358
     *
359
     * @return array<string|array<mixed,mixed>>
360
     *
361
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
362
     */
363 5
    public function getActivatedManipulationUnits(string $shipper, bool $fullData = false): array
364
    {
365 5
        return $this->client->getActivatedManipulationUnits($shipper, $fullData);
366
    }
367
368
    /**
369
     * Get all available branches
370
     *
371
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
372
     *
373
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
374
     */
375 1
    public function getBranches(): iterable
376
    {
377 1
        foreach ($this->getShippers() as $shipper) {
378 1
            yield from $this->getBranchesForShipper($shipper);
379
        }
380
    }
381
382
    /**
383
     * Get all available branches for countries
384
     *
385
     * @param array<string> $countries
386
     *
387
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
388
     *
389
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
390
     */
391 1
    public function getBranchesForCountries(array $countries): iterable
392
    {
393 1
        foreach ($this->getShippers() as $shipper) {
394 1
            yield from $this->getBranchesForShipperForCountries($shipper, $countries);
395
        }
396
    }
397
398
    /**
399
     * Get all available branches for given shipper
400
     *
401
     * @param string $shipper
402
     *
403
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
404
     *
405
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
406
     */
407 2
    public function getBranchesForShipper(string $shipper): iterable
408
    {
409 2
        foreach ($this->getServicesForShipper($shipper) as $service) {
410 2
            yield from $this->getBranchesForShipperService($shipper, $service);
411
        }
412
    }
413
414
    /**
415
     * Get all available branches for given shipper for countries
416
     *
417
     * @param string        $shipper
418
     * @param array<string> $countries
419
     *
420
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
421
     *
422
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
423
     */
424 2
    public function getBranchesForShipperForCountries(string $shipper, array $countries): iterable
425
    {
426 2
        foreach ($this->getServicesForShipper($shipper) as $service) {
427 2
            yield from $this->getBranchesForShipperServiceForCountries($shipper, $service, $countries);
428
        }
429
    }
430
431
    /**
432
     * Get services for shipper
433
     *
434
     * @param string $shipper
435
     *
436
     * @return iterable<string|null>
437
     *
438
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
439
     */
440 4
    private function getServicesForShipper(string $shipper): iterable
441
    {
442 4
        $services = $this->getServices($shipper);
443
444 4
        if (count($services) === 0) {
445 1
            return yield from [null];
446
        }
447
448 3
        foreach (array_keys($services) as $service) {
449 3
            yield (string) $service;
450
        }
451
    }
452
453
    /**
454
     * Get all available branches for given shipper and service type for countries
455
     *
456
     * @param string        $shipper
457
     * @param string|null   $service
458
     * @param array<string> $countries
459
     *
460
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
461
     *
462
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
463
     */
464 4
    public function getBranchesForShipperServiceForCountries(
465
        string $shipper,
466
        ?string $service,
467
        array $countries
468
    ): iterable {
469 4
        foreach ($this->getAllBranchesForShipperServiceForCountries($shipper, $service, $countries) as $branch) {
470 4
            if (in_array($branch->getCountry(), $countries)) {
471 4
                yield $branch;
472
            }
473
        }
474
    }
475
476
    /**
477
     * Get all available branches for given shipper and service type filtered by countries if possible
478
     *
479
     * @param string        $shipper
480
     * @param string|null   $service
481
     * @param array<string> $countries
482
     *
483
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
484
     *
485
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
486
     */
487 4
    private function getAllBranchesForShipperServiceForCountries(
488
        string $shipper,
489
        ?string $service,
490
        array $countries
491
    ): iterable {
492 4
        if (Shipper::hasBranchCountryFilterSupport($shipper, $service) === false) {
493 2
            return yield from $this->getBranchesForShipperService($shipper, $service);
494
        }
495
496 3
        foreach ($countries as $country) {
497 3
            yield from $this->getBranchesForShipperService($shipper, $service, $country);
498
        }
499
    }
500
501
    /**
502
     * Get all available branches for given shipper and service type
503
     *
504
     * @param string      $shipper
505
     * @param string|null $service
506
     * @param string|null $country
507
     *
508
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
509
     *
510
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
511
     */
512 7
    public function getBranchesForShipperService(string $shipper, ?string $service, ?string $country = null): iterable
513
    {
514 7
        $useFullBranchRequest = Shipper::hasFullBranchesSupport($shipper, $service);
515
516 7
        foreach ($this->client->getBranches($shipper, $service, $country, fullBranchesRequest: $useFullBranchRequest, gzip: true) as $branch) {
517 3
            yield Branch::newInstanceFromData($shipper, $service, $branch);
518
        }
519
    }
520
521
    /**
522
     * Get all available branches for given shipper
523
     *
524
     * @param string      $shipper
525
     * @param string      $country
526
     * @param string      $city
527
     * @param string|null $postcode
528
     * @param string|null $street
529
     * @param int|null    $maxResults
530
     * @param float|null  $radius
531
     * @param string|null $type
532
     *
533
     * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[]
534
     *
535
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
536
     */
537 5
    public function getBranchesForLocation(
538
        string $shipper,
539
        string $country,
540
        string $city,
541
        ?string $postcode = null,
542
        ?string $street = null,
543
        ?int $maxResults = null,
544
        ?float $radius = null,
545
        ?string $type = null,
546
    ): iterable {
547 5
        $branches = $this->client->getBranchesForLocation(
548
            $shipper,
549
            $country,
550
            $city,
551
            $postcode,
552
            $street,
553
            $maxResults,
554
            $radius,
555
            $type,
556
        );
557
558 4
        foreach ($branches as $branch) {
559 2
            yield Branch::newInstanceFromData($shipper, null, $branch);
560
        }
561
    }
562
563
    /**
564
     * Returns list of countries where service with cash-on-delivery payment type is available in
565
     *
566
     * @param string $shipper
567
     *
568
     * @return array<array<int|string,array<string,array<string,mixed>>>>
569
     *
570
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
571
     */
572 3
    public function getCodCountries(string $shipper): array
573
    {
574 3
        return $this->client->getCodCountries($shipper);
575
    }
576
577
    /**
578
     * Returns list of countries where service is available in
579
     *
580
     * @param string $shipper
581
     *
582
     * @return array<array<int|string,string>>
583
     *
584
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
585
     */
586 3
    public function getCountries(string $shipper): array
587
    {
588 3
        return $this->client->getCountries($shipper);
589
    }
590
591
    /**
592
     * Returns available branches for the given shipper and its service
593
     *
594
     * @param string      $shipper
595
     * @param string      $service
596
     * @param string|null $country
597
     *
598
     * @return \Generator|\Inspirum\Balikobot\Model\Values\PostCode[]
599
     *
600
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
601
     */
602 4
    public function getPostCodes(string $shipper, string $service, ?string $country = null): iterable
603
    {
604 4
        foreach ($this->client->getPostCodes($shipper, $service, $country) as $postcode) {
605 2
            yield PostCode::newInstanceFromData($shipper, $service, $postcode);
606
        }
607
    }
608
609
    /**
610
     * Check package(s) data
611
     *
612
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
613
     *
614
     * @return void
615
     *
616
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
617
     */
618 3
    public function checkPackages(PackageCollection $packages): void
619
    {
620 3
        $this->client->checkPackages($packages->getShipper(), $packages->toArray());
621
    }
622
623
    /**
624
     * Returns available manipulation units for the given shipper
625
     *
626
     * @param string $shipper
627
     * @param bool   $fullData
628
     *
629
     * @return array<string|array<mixed,mixed>>
630
     *
631
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
632
     */
633 5
    public function getAdrUnits(string $shipper, bool $fullData = false): array
634
    {
635 5
        return $this->client->getAdrUnits($shipper, $fullData);
636
    }
637
638
    /**
639
     * Returns available detailed manipulation units for the given shipper
640
     *
641
     * @param string $shipper
642
     *
643
     * @return array<string,\Inspirum\Balikobot\Model\Values\AdrUnit>
644
     *
645
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
646
     */
647 4
    public function getFullAdrUnits(string $shipper): array
648
    {
649 4
        $response = $this->client->getFullAdrUnits($shipper);
650
651 3
        $units = [];
652
653 3
        foreach ($response as $code => $unit) {
654 2
            $units[$code] = AdrUnit::newInstanceFromData($shipper, $unit);
655
        }
656
657 3
        return $units;
658
    }
659
660
    /**
661
     * Returns available activated services for the given shipper
662
     *
663
     * @param string $shipper
664
     *
665
     * @return array<string,mixed>
666
     *
667
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
668
     */
669 3
    public function getActivatedServices(string $shipper): array
670
    {
671 3
        return $this->client->getActivatedServices($shipper);
672
    }
673
674
    /**
675
     * Order shipments from place B (typically supplier / previous consignee) to place A (shipping point)
676
     *
677
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
678
     *
679
     * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[]
680
     *
681
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
682
     */
683 5
    public function orderB2AShipment(PackageCollection $packages): OrderedPackageCollection
684
    {
685 5
        $response = $this->client->orderB2AShipment($packages->getShipper(), $packages->toArray());
686
687 4
        $orderedPackages = new OrderedPackageCollection();
688
689 4
        foreach ($response as $i => $package) {
690 4
            $package[Option::EID] = (string) $packages->offsetGet($i)->getEID();
691 4
            $orderedPackage       = OrderedPackage::newInstanceFromData($packages->getShipper(), $package);
692 4
            $orderedPackages->add($orderedPackage);
693
        }
694
695 4
        return $orderedPackages;
696
    }
697
698
    /**
699
     * Get PDF link with signed consignment delivery document by the recipient
700
     *
701
     * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package
702
     *
703
     * @return string
704
     *
705
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
706
     */
707 2
    public function getProofOfDelivery(OrderedPackage $package): string
708
    {
709 2
        $packages = new OrderedPackageCollection();
710 2
        $packages->add($package);
711
712 2
        return $this->getProofOfDeliveries($packages)[0];
713
    }
714
715
    /**
716
     * Get array of PDF links with signed consignment delivery document by the recipient
717
     *
718
     * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages
719
     *
720
     * @return array<string>
721
     *
722
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
723
     */
724 6
    public function getProofOfDeliveries(OrderedPackageCollection $packages): array
725
    {
726 6
        return $this->client->getProofOfDeliveries($packages->getShipper(), $packages->getCarrierIds());
727
    }
728
729
    /**
730
     * Get the price of carriage at consignment level
731
     *
732
     * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages
733
     *
734
     * @return \Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection|\Inspirum\Balikobot\Model\Values\PackageTransportCost[]
735
     *
736
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
737
     */
738 4
    public function getTransportCosts(PackageCollection $packages): PackageTransportCostCollection
739
    {
740 4
        $response = $this->client->getTransportCosts($packages->getShipper(), $packages->toArray());
741
742 3
        $transportCosts = new PackageTransportCostCollection($packages->getShipper());
743
744 3
        foreach ($response as $package) {
745 3
            $transportCost = PackageTransportCost::newInstanceFromData($packages->getShipper(), $package);
746 3
            $transportCosts->add($transportCost);
747
        }
748
749 3
        return $transportCosts;
750
    }
751
752
    /**
753
     * Get information on individual countries of the world
754
     *
755
     * @return array<string,\Inspirum\Balikobot\Model\Values\Country>|\Inspirum\Balikobot\Model\Values\Country[]
756
     *
757
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
758
     */
759 3
    public function getCountriesData(): array
760
    {
761 3
        $response = $this->client->getCountriesData();
762
763 3
        $countries = [];
764
765 3
        foreach ($response as $code => $country) {
766 2
            $countries[$code] = Country::newInstanceFromData($country);
767
        }
768
769 3
        return $countries;
770
    }
771
772
    /**
773
     * Get news in the Balikobot API
774
     *
775
     * @return array<string,mixed>
776
     *
777
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
778
     */
779 1
    public function getChangelog(): array
780
    {
781 1
        return $this->client->getChangelog();
782
    }
783
784
    /**
785
     * Get list of additional services by individual transport services
786
     *
787
     * @param string $shipper
788
     *
789
     * @return array<string,array<string,mixed>>
790
     *
791
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
792
     */
793 3
    public function getAddAttributes(string $shipper): array
794
    {
795 3
        return $this->client->getAddAttributes($shipper);
796
    }
797
798
    /**
799
     * Get list of additional services by individual transport services
800
     *
801
     * @param string      $shipper
802
     * @param string|null $service
803
     * @param bool        $fullData
804
     *
805
     * @return array<string,string|array<string,string|array<mixed,mixed>>>
806
     *
807
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
808
     */
809 8
    public function getAddServiceOptions(string $shipper, ?string $service = null, bool $fullData = false): array
810
    {
811 8
        return $this->client->getAddServiceOptions($shipper, $service, $fullData);
812
    }
813
814
    /**
815
     * Get info about used API keys
816
     *
817
     * @return array<string,mixed>
818
     *
819
     * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface
820
     */
821 2
    public function getAccountInfo(): array
822
    {
823 2
        return $this->client->getAccountInfo();
824
    }
825
}
826