-
Notifications
You must be signed in to change notification settings - Fork 19
/
Availability.php
66 lines (53 loc) · 1.35 KB
/
Availability.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php declare(strict_types=1);
namespace MpApiClient\Article\Entity\Common;
use JsonSerializable;
use MpApiClient\Common\Util\JsonSerializeEntityTrait;
class Availability implements JsonSerializable
{
use JsonSerializeEntityTrait;
private StatusEnum $status;
private int $inStock;
public function __construct(StatusEnum $status, int $inStock)
{
$this->status = $status;
$this->inStock = $inStock;
}
/**
* @param array<string, mixed> $data
*
* @internal
*/
public static function createFromApi(array $data): self
{
return new self(
new StatusEnum((string) $data[StatusEnum::KEY_NAME]),
(int) $data['in_stock'],
);
}
/**
* @return array<string, mixed>
*/
public function getArrayForApi(): array
{
return [
StatusEnum::KEY_NAME => $this->getStatus()->getValue(),
'in_stock' => $this->getInStock(),
];
}
public function getStatus(): StatusEnum
{
return $this->status;
}
public function setStatus(StatusEnum $status): void
{
$this->status = $status;
}
public function getInStock(): int
{
return $this->inStock;
}
public function setInStock(int $inStock): void
{
$this->inStock = $inStock;
}
}