ldc-cocotte/domain/Models/Entities/Shopper.php
2026-10-27 09:58:12 +01:00

56 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Domain\Models\Entities;
use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;
use Domain\Models\ValueObjects\Email;
use Domain\Models\ValueObjects\Entities\ShopperId;
use Domain\Models\ValueObjects\Matricule;
use Shared\DDD\Entity;
/** @implements \Shared\DDD\Entity<\Domain\Models\ValueObjects\Entities\ShopperId> */
final readonly class Shopper implements Entity
{
public function __construct(
private readonly ShopperId $id,
public readonly Email $email,
public readonly Matricule $matricule,
public readonly string $nom,
public readonly string $prenom,
public readonly CarbonInterface $startDate,
public readonly ?CarbonInterface $endDate,
public readonly string $etablissement,
public readonly string $site,
public readonly string $service
) {
if (trim($nom) === '') {
throw new \DomainException('nom cannot be empty');
}
if (trim($prenom) === '') {
throw new \DomainException('prenom cannot be empty');
}
if (trim($etablissement) === '') {
throw new \DomainException('etablissement cannot be empty');
}
if (trim($site) === '') {
throw new \DomainException('site cannot be empty');
}
if (trim($service) === '') {
throw new \DomainException('service cannot be empty');
}
}
#[\Override]
public function id(): ShopperId
{
return $this->id;
}
public function isActive(): bool
{
return $this->endDate === null || $this->endDate->greaterThan(CarbonImmutable::now());
}
}