|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Paddle\SDK\Notifications\Entities\Simulation; |
| 6 | + |
| 7 | +use Paddle\SDK\FiltersUndefined; |
| 8 | +use Paddle\SDK\Notifications\Entities\DateTime; |
| 9 | +use Paddle\SDK\Notifications\Entities\Shared\CountryCode; |
| 10 | +use Paddle\SDK\Notifications\Entities\Shared\CustomData; |
| 11 | +use Paddle\SDK\Notifications\Entities\Shared\ImportMeta; |
| 12 | +use Paddle\SDK\Notifications\Entities\Shared\Status; |
| 13 | +use Paddle\SDK\Notifications\Entities\Simulation\Traits\OptionalProperties; |
| 14 | +use Paddle\SDK\Undefined; |
| 15 | + |
| 16 | +final class Address implements SimulationEntity |
| 17 | +{ |
| 18 | + use OptionalProperties; |
| 19 | + use FiltersUndefined; |
| 20 | + |
| 21 | + public function __construct( |
| 22 | + public readonly string|Undefined $id = new Undefined(), |
| 23 | + public readonly string|Undefined|null $description = new Undefined(), |
| 24 | + public readonly string|Undefined|null $firstLine = new Undefined(), |
| 25 | + public readonly string|Undefined|null $secondLine = new Undefined(), |
| 26 | + public readonly string|Undefined|null $city = new Undefined(), |
| 27 | + public readonly string|Undefined|null $postalCode = new Undefined(), |
| 28 | + public readonly string|Undefined|null $region = new Undefined(), |
| 29 | + public readonly CountryCode|Undefined $countryCode = new Undefined(), |
| 30 | + public readonly CustomData|Undefined|null $customData = new Undefined(), |
| 31 | + public readonly Status|Undefined $status = new Undefined(), |
| 32 | + public readonly \DateTimeInterface|Undefined $createdAt = new Undefined(), |
| 33 | + public readonly \DateTimeInterface|Undefined $updatedAt = new Undefined(), |
| 34 | + public readonly ImportMeta|Undefined|null $importMeta = new Undefined(), |
| 35 | + public readonly string|Undefined|null $customerId = new Undefined(), |
| 36 | + ) { |
| 37 | + } |
| 38 | + |
| 39 | + public static function from(array $data): self |
| 40 | + { |
| 41 | + return new self( |
| 42 | + id: self::optional($data, 'id'), |
| 43 | + description: self::optional($data, 'description'), |
| 44 | + firstLine: self::optional($data, 'first_line'), |
| 45 | + secondLine: self::optional($data, 'second_line'), |
| 46 | + city: self::optional($data, 'city'), |
| 47 | + postalCode: self::optional($data, 'postal_code'), |
| 48 | + region: self::optional($data, 'region'), |
| 49 | + countryCode: self::optional($data, 'country_code', fn ($value) => CountryCode::from($value)), |
| 50 | + customData: self::optional($data, 'custom_data', fn ($value) => new CustomData($value)), |
| 51 | + status: self::optional($data, 'status', fn ($value) => Status::from($value)), |
| 52 | + createdAt: self::optional($data, 'created_at', fn ($value) => DateTime::from($value)), |
| 53 | + updatedAt: self::optional($data, 'updated_at', fn ($value) => DateTime::from($value)), |
| 54 | + importMeta: self::optional($data, 'import_meta', fn ($value) => ImportMeta::from($value)), |
| 55 | + customerId: self::optional($data, 'customer_id'), |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + public function jsonSerialize(): mixed |
| 60 | + { |
| 61 | + return $this->filterUndefined([ |
| 62 | + 'id' => $this->id, |
| 63 | + 'description' => $this->description, |
| 64 | + 'first_line' => $this->firstLine, |
| 65 | + 'second_line' => $this->secondLine, |
| 66 | + 'city' => $this->city, |
| 67 | + 'postal_code' => $this->postalCode, |
| 68 | + 'region' => $this->region, |
| 69 | + 'country_code' => $this->countryCode, |
| 70 | + 'custom_data' => $this->customData, |
| 71 | + 'status' => $this->status, |
| 72 | + 'created_at' => $this->createdAt, |
| 73 | + 'updated_at' => $this->updatedAt, |
| 74 | + 'import_meta' => $this->importMeta, |
| 75 | + 'customer_id' => $this->customerId, |
| 76 | + ]); |
| 77 | + } |
| 78 | +} |
0 commit comments