ldc-boutique-cnc-sable/domain/Models/Entities/Shopper.php

51 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?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 Domain\Models\ValueObjects\ShopperEstablishmentCode;
use Domain\Models\ValueObjects\ShopperServiceCode;
use Domain\Models\ValueObjects\ShopperSiteCode;
2026-06-14 21:32:07 +02:00
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 ShopperEstablishmentCode $etablissement,
public readonly ShopperSiteCode $site,
public readonly ShopperServiceCode $service
2026-06-14 21:32:07 +02:00
) {
if (trim($nom) === '') {
throw new \DomainException('nom cannot be empty');
}
if (trim($prenom) === '') {
throw new \DomainException('prenom cannot be empty');
}
}
#[\Override]
public function id(): ShopperId
{
return $this->id;
}
public function isActive(): bool
{
return $this->endDate === null || $this->endDate->greaterThan(CarbonImmutable::now());
}
}