<?php
declare(strict_types=1);
namespace Bodymed\Webshop\Messenger\Messages\User;
use Bodymed\Webshop\Messenger\DistributedMessageInterface;
/**
* Sent, when a BusinessPartner was created and should get a webshop-login
*/
class CreateWebshopCustomerFromBusinessPartner implements DistributedMessageInterface
{
public const SUBJECT = 'f9636140-464e-46a1-be03-856e73e78bd1';
private string $email;
private array $payload;
private \DateTimeImmutable $when;
public function __construct(array $payload, \DateTimeImmutable $when = null)
{
$this->email = (string) $payload['email'];
$this->payload = $payload;
$this->when = $when ?? new \DateTimeImmutable();
}
public static function getSubject(): string
{
return self::SUBJECT;
}
public function toPayload(): array
{
return \array_merge($this->payload, [
'when' => $this->when,
]);
}
public static function fromPayload(array $data): CreateWebshopCustomerFromBusinessPartner
{
$static = new CreateWebshopCustomerFromBusinessPartner($data);
$static->when = new \DateTimeImmutable(
$data['when']['date'],
new \DateTimeZone($data['when']['timezone'])
);
return $static;
}
public function jsonSerialize()
{
return $this->toPayload();
}
public function getEmail(): string
{
return $this->email;
}
public function getPayload(): array
{
return $this->payload;
}
public function getWhen(): \DateTimeImmutable
{
return $this->when;
}
}