| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
/** |
| 10 |
* A custom attribute value. Each custom attribute value has a corresponding |
| 11 |
* `CustomAttributeDefinition` object. |
| 12 |
*/ |
| 13 |
class CustomAttribute implements \JsonSerializable |
| 14 |
{ |
| 15 |
/** |
| 16 |
* @var array |
| 17 |
*/ |
| 18 |
private $key = []; |
| 19 |
|
| 20 |
/** |
| 21 |
* @var array |
| 22 |
*/ |
| 23 |
private $value = []; |
| 24 |
|
| 25 |
/** |
| 26 |
* @var int|null |
| 27 |
*/ |
| 28 |
private $version; |
| 29 |
|
| 30 |
/** |
| 31 |
* @var string|null |
| 32 |
*/ |
| 33 |
private $visibility; |
| 34 |
|
| 35 |
/** |
| 36 |
* @var CustomAttributeDefinition|null |
| 37 |
*/ |
| 38 |
private $definition; |
| 39 |
|
| 40 |
/** |
| 41 |
* @var string|null |
| 42 |
*/ |
| 43 |
private $updatedAt; |
| 44 |
|
| 45 |
/** |
| 46 |
* @var string|null |
| 47 |
*/ |
| 48 |
private $createdAt; |
| 49 |
|
| 50 |
/** |
| 51 |
* Returns Key. |
| 52 |
* The identifier |
| 53 |
* of the custom attribute definition and its corresponding custom attributes. This value |
| 54 |
* can be a simple key, which is the key that is provided when the custom attribute definition |
| 55 |
* is created, or a qualified key, if the requesting |
| 56 |
* application is not the definition owner. The qualified key consists of the application ID |
| 57 |
* of the custom attribute definition owner |
| 58 |
* followed by the simple key that was provided when the definition was created. It has the |
| 59 |
* format application_id:simple key. |
| 60 |
* |
| 61 |
* The value for a simple key can contain up to 60 alphanumeric characters, periods (.), |
| 62 |
* underscores (_), and hyphens (-). |
| 63 |
*/ |
| 64 |
public function getKey(): ?string |
| 65 |
{ |
| 66 |
if (count($this->key) == 0) { |
| 67 |
return null; |
| 68 |
} |
| 69 |
return $this->key['value']; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Sets Key. |
| 74 |
* The identifier |
| 75 |
* of the custom attribute definition and its corresponding custom attributes. This value |
| 76 |
* can be a simple key, which is the key that is provided when the custom attribute definition |
| 77 |
* is created, or a qualified key, if the requesting |
| 78 |
* application is not the definition owner. The qualified key consists of the application ID |
| 79 |
* of the custom attribute definition owner |
| 80 |
* followed by the simple key that was provided when the definition was created. It has the |
| 81 |
* format application_id:simple key. |
| 82 |
* |
| 83 |
* The value for a simple key can contain up to 60 alphanumeric characters, periods (.), |
| 84 |
* underscores (_), and hyphens (-). |
| 85 |
* |
| 86 |
* @maps key |
| 87 |
*/ |
| 88 |
public function setKey(?string $key): void |
| 89 |
{ |
| 90 |
$this->key['value'] = $key; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Unsets Key. |
| 95 |
* The identifier |
| 96 |
* of the custom attribute definition and its corresponding custom attributes. This value |
| 97 |
* can be a simple key, which is the key that is provided when the custom attribute definition |
| 98 |
* is created, or a qualified key, if the requesting |
| 99 |
* application is not the definition owner. The qualified key consists of the application ID |
| 100 |
* of the custom attribute definition owner |
| 101 |
* followed by the simple key that was provided when the definition was created. It has the |
| 102 |
* format application_id:simple key. |
| 103 |
* |
| 104 |
* The value for a simple key can contain up to 60 alphanumeric characters, periods (.), |
| 105 |
* underscores (_), and hyphens (-). |
| 106 |
*/ |
| 107 |
public function unsetKey(): void |
| 108 |
{ |
| 109 |
$this->key = []; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Returns Value. |
| 114 |
* The value assigned to the custom attribute. It is validated against the custom |
| 115 |
* attribute definition's schema on write operations. For more information about custom |
| 116 |
* attribute values, |
| 117 |
* see [Custom Attributes Overview](https://developer.squareup. |
| 118 |
* com/docs/devtools/customattributes/overview). |
| 119 |
* |
| 120 |
* @return mixed |
| 121 |
*/ |
| 122 |
public function getValue() |
| 123 |
{ |
| 124 |
if (count($this->value) == 0) { |
| 125 |
return null; |
| 126 |
} |
| 127 |
return $this->value['value']; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Sets Value. |
| 132 |
* The value assigned to the custom attribute. It is validated against the custom |
| 133 |
* attribute definition's schema on write operations. For more information about custom |
| 134 |
* attribute values, |
| 135 |
* see [Custom Attributes Overview](https://developer.squareup. |
| 136 |
* com/docs/devtools/customattributes/overview). |
| 137 |
* |
| 138 |
* @maps value |
| 139 |
* |
| 140 |
* @param mixed $value |
| 141 |
*/ |
| 142 |
public function setValue($value): void |
| 143 |
{ |
| 144 |
$this->value['value'] = $value; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Unsets Value. |
| 149 |
* The value assigned to the custom attribute. It is validated against the custom |
| 150 |
* attribute definition's schema on write operations. For more information about custom |
| 151 |
* attribute values, |
| 152 |
* see [Custom Attributes Overview](https://developer.squareup. |
| 153 |
* com/docs/devtools/customattributes/overview). |
| 154 |
*/ |
| 155 |
public function unsetValue(): void |
| 156 |
{ |
| 157 |
$this->value = []; |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Returns Version. |
| 162 |
* Read only. The current version of the custom attribute. This field is incremented when the custom |
| 163 |
* attribute is changed. |
| 164 |
* When updating an existing custom attribute value, you can provide this field |
| 165 |
* and specify the current version of the custom attribute to enable |
| 166 |
* [optimistic concurrency](https://developer.squareup.com/docs/build-basics/common-api- |
| 167 |
* patterns/optimistic-concurrency). |
| 168 |
* This field can also be used to enforce strong consistency for reads. For more information about |
| 169 |
* strong consistency for reads, |
| 170 |
* see [Custom Attributes Overview](https://developer.squareup. |
| 171 |
* com/docs/devtools/customattributes/overview). |
| 172 |
*/ |
| 173 |
public function getVersion(): ?int |
| 174 |
{ |
| 175 |
return $this->version; |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Sets Version. |
| 180 |
* Read only. The current version of the custom attribute. This field is incremented when the custom |
| 181 |
* attribute is changed. |
| 182 |
* When updating an existing custom attribute value, you can provide this field |
| 183 |
* and specify the current version of the custom attribute to enable |
| 184 |
* [optimistic concurrency](https://developer.squareup.com/docs/build-basics/common-api- |
| 185 |
* patterns/optimistic-concurrency). |
| 186 |
* This field can also be used to enforce strong consistency for reads. For more information about |
| 187 |
* strong consistency for reads, |
| 188 |
* see [Custom Attributes Overview](https://developer.squareup. |
| 189 |
* com/docs/devtools/customattributes/overview). |
| 190 |
* |
| 191 |
* @maps version |
| 192 |
*/ |
| 193 |
public function setVersion(?int $version): void |
| 194 |
{ |
| 195 |
$this->version = $version; |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Returns Visibility. |
| 200 |
* The level of permission that a seller or other applications requires to |
| 201 |
* view this custom attribute definition. |
| 202 |
* The `Visibility` field controls who can read and write the custom attribute values |
| 203 |
* and custom attribute definition. |
| 204 |
*/ |
| 205 |
public function getVisibility(): ?string |
| 206 |
{ |
| 207 |
return $this->visibility; |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* Sets Visibility. |
| 212 |
* The level of permission that a seller or other applications requires to |
| 213 |
* view this custom attribute definition. |
| 214 |
* The `Visibility` field controls who can read and write the custom attribute values |
| 215 |
* and custom attribute definition. |
| 216 |
* |
| 217 |
* @maps visibility |
| 218 |
*/ |
| 219 |
public function setVisibility(?string $visibility): void |
| 220 |
{ |
| 221 |
$this->visibility = $visibility; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Returns Definition. |
| 226 |
* Represents a definition for custom attribute values. A custom attribute definition |
| 227 |
* specifies the key, visibility, schema, and other properties for a custom attribute. |
| 228 |
*/ |
| 229 |
public function getDefinition(): ?CustomAttributeDefinition |
| 230 |
{ |
| 231 |
return $this->definition; |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* Sets Definition. |
| 236 |
* Represents a definition for custom attribute values. A custom attribute definition |
| 237 |
* specifies the key, visibility, schema, and other properties for a custom attribute. |
| 238 |
* |
| 239 |
* @maps definition |
| 240 |
*/ |
| 241 |
public function setDefinition(?CustomAttributeDefinition $definition): void |
| 242 |
{ |
| 243 |
$this->definition = $definition; |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* Returns Updated At. |
| 248 |
* The timestamp that indicates when the custom attribute was created or was most recently |
| 249 |
* updated, in RFC 3339 format. |
| 250 |
*/ |
| 251 |
public function getUpdatedAt(): ?string |
| 252 |
{ |
| 253 |
return $this->updatedAt; |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Sets Updated At. |
| 258 |
* The timestamp that indicates when the custom attribute was created or was most recently |
| 259 |
* updated, in RFC 3339 format. |
| 260 |
* |
| 261 |
* @maps updated_at |
| 262 |
*/ |
| 263 |
public function setUpdatedAt(?string $updatedAt): void |
| 264 |
{ |
| 265 |
$this->updatedAt = $updatedAt; |
| 266 |
} |
| 267 |
|
| 268 |
/** |
| 269 |
* Returns Created At. |
| 270 |
* The timestamp that indicates when the custom attribute was created, in RFC 3339 format. |
| 271 |
*/ |
| 272 |
public function getCreatedAt(): ?string |
| 273 |
{ |
| 274 |
return $this->createdAt; |
| 275 |
} |
| 276 |
|
| 277 |
/** |
| 278 |
* Sets Created At. |
| 279 |
* The timestamp that indicates when the custom attribute was created, in RFC 3339 format. |
| 280 |
* |
| 281 |
* @maps created_at |
| 282 |
*/ |
| 283 |
public function setCreatedAt(?string $createdAt): void |
| 284 |
{ |
| 285 |
$this->createdAt = $createdAt; |
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* Encode this object to JSON |
| 290 |
* |
| 291 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 292 |
* are set. (default: false) |
| 293 |
* |
| 294 |
* @return array|stdClass |
| 295 |
*/ |
| 296 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 297 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 298 |
{ |
| 299 |
$json = []; |
| 300 |
if (!empty($this->key)) { |
| 301 |
$json['key'] = $this->key['value']; |
| 302 |
} |
| 303 |
if (!empty($this->value)) { |
| 304 |
$json['value'] = $this->value['value']; |
| 305 |
} |
| 306 |
if (isset($this->version)) { |
| 307 |
$json['version'] = $this->version; |
| 308 |
} |
| 309 |
if (isset($this->visibility)) { |
| 310 |
$json['visibility'] = $this->visibility; |
| 311 |
} |
| 312 |
if (isset($this->definition)) { |
| 313 |
$json['definition'] = $this->definition; |
| 314 |
} |
| 315 |
if (isset($this->updatedAt)) { |
| 316 |
$json['updated_at'] = $this->updatedAt; |
| 317 |
} |
| 318 |
if (isset($this->createdAt)) { |
| 319 |
$json['created_at'] = $this->createdAt; |
| 320 |
} |
| 321 |
$json = array_filter($json, function ($val) { |
| 322 |
return $val !== null; |
| 323 |
}); |
| 324 |
|
| 325 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 326 |
} |
| 327 |
} |
| 328 |
|