<?php
declare(strict_types=1);
namespace Bodymed\Webshop\Messenger\Messages\User;
use Bodymed\Webshop\Messenger\DistributedMessageInterface;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
class CustomerNumberUpdated implements DistributedMessageInterface
{
public const SUBJECT = '86645d90-cfae-415e-86a4-cd4f49dba4b8';
private UuidInterface $userId;
private string $webshopCustomerId;
private string $customerNumber;
private \DateTimeImmutable $when;
public function __construct(
UuidInterface $userId,
string $webshopCustomerId,
string $customerNumber,
?\DateTimeImmutable $when = null
) {
$this->userId = $userId;
$this->webshopCustomerId = $webshopCustomerId;
$this->customerNumber = $customerNumber;
$this->when = $when ?? new \DateTimeImmutable();
}
public static function getSubject(): string
{
return self::SUBJECT;
}
public function toPayload(): array
{
return [
'userId' => $this->userId->toString(),
'webshopCustomerId' => $this->webshopCustomerId,
'customerNumber' => $this->customerNumber,
'when' => $this->when,
];
}
public static function fromPayload(array $data): CustomerNumberUpdated
{
$static = new static(Uuid::fromString($data['userId']), (string) $data['webshopCustomerId'], (string) $data['customerNumber']);
$when = new \DateTimeImmutable(
$data['when']['date'],
new \DateTimeZone($data['when']['timezone'])
);
$static->when = $when;
return $static;
}
public function jsonSerialize()
{
return $this->toPayload();
}
public function getUserId(): UuidInterface
{
return $this->userId;
}
public function getWebshopCustomerId(): string
{
return $this->webshopCustomerId;
}
public function getCustomerNumber(): string
{
return $this->customerNumber;
}
public function getWhen(): \DateTimeImmutable
{
return $this->when;
}
}