<?php
declare(strict_types=1);
namespace App\Domain\Merchant\Model;
use App\Domain\Shared\Model\Aggregate;
use App\Domain\Shared\Model\TimestampTrait;
use App\Domain\Site\Model\Site;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Uid\Uuid;
class Merchant extends Aggregate implements UserInterface, PasswordAuthenticatedUserInterface
{
use TimestampTrait;
/**
* @var Collection<array-key, Site>
*/
private Collection $sites;
/**
* @var Collection<array-key, MerchantResetPasswordToken>
*/
private Collection $resetPasswordTokens;
public function __construct(
private Uuid $id,
private string $firstName,
private string $lastName,
private string $email,
private string $password,
private MerchantRole $role,
private bool $active,
private ?string $paymentProvider = null
) {
$this->paymentProvider = $paymentProvider;
$this->sites = new ArrayCollection();
$this->resetPasswordTokens = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = null;
}
public function getId(): Uuid
{
return $this->id;
}
public function getFirstName(): string
{
return $this->firstName;
}
public function getLastName(): string
{
return $this->lastName;
}
public function getEmail(): string
{
return $this->email;
}
public function getRole(): MerchantRole
{
return $this->role;
}
public function getPaymentProvider(): ?string
{
return $this->paymentProvider;
}
public function isActive(): bool
{
return $this->active;
}
public function getRoles(): array
{
return [$this->role->value];
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function getUserIdentifier(): string
{
return $this->email;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): void
{
$this->createdAt = $createdAt;
}
public function setUpdatedAt($updatedAt): void
{
$this->updatedAt = $updatedAt;
}
public function setId(Uuid $id): void
{
$this->id = $id;
}
public function setFirstName(string $firstName): void
{
$this->firstName = $firstName;
}
public function setLastName(string $lastName): void
{
$this->lastName = $lastName;
}
public function setEmail(string $email): void
{
$this->email = $email;
}
public function setPassword(string $password): void
{
$this->password = $password;
}
public function setRole(MerchantRole $role): void
{
$this->role = $role;
}
public function setPaymentProvider(?string $paymentProvider): void
{
$this->paymentProvider = $paymentProvider;
}
public function setActive(bool $active): void
{
$this->active = $active;
}
public function addSite(Site $site): void
{
if (!$this->sites->contains($site)) {
$this->sites->add($site);
}
}
public function removeSite(Site $site): void
{
if ($this->sites->contains($site)) {
$this->sites->removeElement($site);
}
}
}