1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace InShore\Bookwhen\Responses\Tickets; |
6
|
|
|
|
7
|
|
|
use InShore\Bookwhen\Contracts\ResponseContract; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @implements ResponseContract<array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}> |
11
|
|
|
*/ |
12
|
|
|
final class RetrieveResponse implements ResponseContract |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param array<array-key, mixed>|null $statusDetails |
|
|
|
|
16
|
|
|
*/ |
17
|
8 |
|
private function __construct( |
18
|
|
|
public readonly bool | null $available, |
19
|
|
|
public readonly null | string $availableFrom, |
20
|
|
|
public readonly null | string $availableTo, |
21
|
|
|
public readonly null | string $builtBasketUrl, |
22
|
|
|
public readonly null | string $builtBasketIframeUrl, |
23
|
|
|
public readonly object $cost, |
24
|
|
|
public readonly bool | null $courseTicket, |
25
|
|
|
public readonly null | string $details, |
26
|
|
|
public readonly bool | null $groupTicket, |
27
|
|
|
public readonly int | null $groupMin, |
28
|
|
|
public readonly int | null $groupMax, |
29
|
|
|
public readonly string $id, |
30
|
|
|
public readonly int | null $numberIssued, |
31
|
|
|
public readonly int | null $numberTaken, |
32
|
|
|
public readonly null | string $title |
33
|
|
|
) { |
34
|
8 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Acts as static factory, and returns a new Response instance. |
38
|
|
|
* |
39
|
|
|
* @param array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null} $attributes |
|
|
|
|
40
|
|
|
*/ |
41
|
8 |
|
public static function from(array $attributes, $included = []): self |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
|
44
|
8 |
|
$cost = new \stdClass(); |
45
|
8 |
|
if (!empty($attributes['attributes']['cost'])) { |
46
|
2 |
|
$cost->currencyCode = $attributes['attributes']['cost']['currency_code']; |
47
|
2 |
|
$cost->net = $attributes['attributes']['cost']['net']; |
48
|
2 |
|
$cost->tax = $attributes['attributes']['cost']['tax']; |
49
|
|
|
} |
50
|
|
|
|
51
|
8 |
|
return new self( |
52
|
8 |
|
$attributes['attributes']['available'] ?? null, |
53
|
8 |
|
$attributes['attributes']['available_from'] ?? null, |
54
|
8 |
|
$attributes['attributes']['available_to'] ?? null, |
55
|
8 |
|
$attributes['attributes']['built_basket_url'] ?? null, |
56
|
8 |
|
$attributes['attributes']['built_basket_iframe_url'] ?? null, |
57
|
8 |
|
$cost, |
58
|
8 |
|
$attributes['attributes']['course_ticket'] ?? null, |
59
|
8 |
|
$attributes['attributes']['details'] ?? null, |
60
|
8 |
|
$attributes['attributes']['group_ticket'] ?? null, |
61
|
8 |
|
$attributes['attributes']['group_min'] ?? null, |
62
|
8 |
|
$attributes['attributes']['group_max'] ?? null, |
63
|
8 |
|
$attributes['id'], |
64
|
8 |
|
$attributes['attributes']['number_issued'] ?? null, |
65
|
8 |
|
$attributes['attributes']['number_taken'] ?? null, |
66
|
8 |
|
$attributes['attributes']['title'] ?? null, |
67
|
8 |
|
); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|