| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
/** |
| 10 |
* Options to control how to override the default behavior of the specified modifier. |
| 11 |
*/ |
| 12 |
class CatalogModifierOverride implements \JsonSerializable |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @var string |
| 16 |
*/ |
| 17 |
private $modifierId; |
| 18 |
|
| 19 |
/** |
| 20 |
* @var array |
| 21 |
*/ |
| 22 |
private $onByDefault = []; |
| 23 |
|
| 24 |
/** |
| 25 |
* @param string $modifierId |
| 26 |
*/ |
| 27 |
public function __construct(string $modifierId) |
| 28 |
{ |
| 29 |
$this->modifierId = $modifierId; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Returns Modifier Id. |
| 34 |
* The ID of the `CatalogModifier` whose default behavior is being overridden. |
| 35 |
*/ |
| 36 |
public function getModifierId(): string |
| 37 |
{ |
| 38 |
return $this->modifierId; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Sets Modifier Id. |
| 43 |
* The ID of the `CatalogModifier` whose default behavior is being overridden. |
| 44 |
* |
| 45 |
* @required |
| 46 |
* @maps modifier_id |
| 47 |
*/ |
| 48 |
public function setModifierId(string $modifierId): void |
| 49 |
{ |
| 50 |
$this->modifierId = $modifierId; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Returns On by Default. |
| 55 |
* If `true`, this `CatalogModifier` should be selected by default for this `CatalogItem`. |
| 56 |
*/ |
| 57 |
public function getOnByDefault(): ?bool |
| 58 |
{ |
| 59 |
if (count($this->onByDefault) == 0) { |
| 60 |
return null; |
| 61 |
} |
| 62 |
return $this->onByDefault['value']; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Sets On by Default. |
| 67 |
* If `true`, this `CatalogModifier` should be selected by default for this `CatalogItem`. |
| 68 |
* |
| 69 |
* @maps on_by_default |
| 70 |
*/ |
| 71 |
public function setOnByDefault(?bool $onByDefault): void |
| 72 |
{ |
| 73 |
$this->onByDefault['value'] = $onByDefault; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Unsets On by Default. |
| 78 |
* If `true`, this `CatalogModifier` should be selected by default for this `CatalogItem`. |
| 79 |
*/ |
| 80 |
public function unsetOnByDefault(): void |
| 81 |
{ |
| 82 |
$this->onByDefault = []; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Encode this object to JSON |
| 87 |
* |
| 88 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 89 |
* are set. (default: false) |
| 90 |
* |
| 91 |
* @return array|stdClass |
| 92 |
*/ |
| 93 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 94 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 95 |
{ |
| 96 |
$json = []; |
| 97 |
$json['modifier_id'] = $this->modifierId; |
| 98 |
if (!empty($this->onByDefault)) { |
| 99 |
$json['on_by_default'] = $this->onByDefault['value']; |
| 100 |
} |
| 101 |
$json = array_filter($json, function ($val) { |
| 102 |
return $val !== null; |
| 103 |
}); |
| 104 |
|
| 105 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 106 |
} |
| 107 |
} |
| 108 |
|