2026-09-21 16:59:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Domain\Models\Entities;
|
|
|
|
|
|
2026-09-24 11:28:29 +02:00
|
|
|
use Domain\Models\ValueObjects\Actor\ActorId;
|
2026-09-21 16:59:26 +02:00
|
|
|
use Domain\Models\ValueObjects\Brand\BrandCode;
|
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponAvailabilityCalendar;
|
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponDiffusion;
|
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponId;
|
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponLegalInformation;
|
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponProduct;
|
|
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponValidity;
|
|
|
|
|
use Domain\Models\ValueObjects\CouponName;
|
|
|
|
|
use Domain\Models\ValueObjects\CouponPicture;
|
|
|
|
|
use Domain\Models\ValueObjects\CouponProductName;
|
|
|
|
|
use Domain\Models\ValueObjects\GS1;
|
|
|
|
|
use Domain\Models\ValueObjects\MoneyAmount;
|
|
|
|
|
use Domain\Models\ValueObjects\ProcessingCode;
|
|
|
|
|
use Shared\DDD\Models\AggregateRoot;
|
|
|
|
|
use Shared\DDD\Models\HasTimestampIdentifier;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @implements \Shared\DDD\Models\AggregateRoot<\Domain\Models\ValueObjects\Coupon\CouponId>
|
|
|
|
|
*/
|
|
|
|
|
final readonly class Coupon implements AggregateRoot, HasTimestampIdentifier
|
|
|
|
|
{
|
|
|
|
|
private function __construct(
|
|
|
|
|
public CouponId $id,
|
|
|
|
|
public CouponName $name,
|
|
|
|
|
public bool $status,
|
|
|
|
|
public CouponProductName $productName,
|
|
|
|
|
public MoneyAmount $amount,
|
|
|
|
|
public CouponPicture $picture,
|
|
|
|
|
public CouponProduct $product,
|
|
|
|
|
public CouponDiffusion $diffusion,
|
|
|
|
|
public CouponAvailabilityCalendar $availability,
|
|
|
|
|
public CouponValidity $validity,
|
2026-09-24 11:28:29 +02:00
|
|
|
/** @var array<int, CouponLegalInformation> $legal */
|
|
|
|
|
public array $legal,
|
2026-09-21 16:59:26 +02:00
|
|
|
public ProcessingCode $code,
|
|
|
|
|
public BrandCode $brandCode,
|
2026-09-24 11:28:29 +02:00
|
|
|
public ActorId $createdBy,
|
|
|
|
|
public ?GS1 $gtin = null,
|
2026-09-21 16:59:26 +02:00
|
|
|
public ?\DateTimeInterface $updatedAt = null,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function id(): CouponId
|
|
|
|
|
{
|
|
|
|
|
return $this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createdAt(): \DateTimeInterface
|
|
|
|
|
{
|
|
|
|
|
return $this->id->toDateTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updatedAt(): ?\DateTimeInterface
|
|
|
|
|
{
|
|
|
|
|
return $this->updatedAt;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-24 11:28:29 +02:00
|
|
|
/**
|
|
|
|
|
* @param array<int, CouponLegalInformation> $legal
|
|
|
|
|
*/
|
2026-09-21 16:59:26 +02:00
|
|
|
public static function create(
|
|
|
|
|
CouponName $name,
|
|
|
|
|
bool $status,
|
|
|
|
|
CouponProductName $productName,
|
|
|
|
|
MoneyAmount $amount,
|
|
|
|
|
CouponPicture $picture,
|
|
|
|
|
CouponProduct $product,
|
|
|
|
|
CouponDiffusion $diffusion,
|
|
|
|
|
CouponAvailabilityCalendar $availability,
|
|
|
|
|
CouponValidity $validity,
|
2026-09-24 11:28:29 +02:00
|
|
|
array $legal,
|
2026-09-21 16:59:26 +02:00
|
|
|
ProcessingCode $code,
|
|
|
|
|
BrandCode $brandCode,
|
2026-09-24 11:28:29 +02:00
|
|
|
ActorId $createdBy,
|
|
|
|
|
?GS1 $gtin = null,
|
2026-09-21 16:59:26 +02:00
|
|
|
?\DateTimeInterface $updatedAt = null,
|
|
|
|
|
): Coupon {
|
|
|
|
|
return new self(
|
|
|
|
|
id: CouponId::generate(),
|
|
|
|
|
name: $name,
|
|
|
|
|
status: $status,
|
|
|
|
|
productName: $productName,
|
|
|
|
|
amount: $amount,
|
|
|
|
|
picture: $picture,
|
|
|
|
|
product: $product,
|
|
|
|
|
diffusion: $diffusion,
|
|
|
|
|
availability: $availability,
|
|
|
|
|
validity: $validity,
|
|
|
|
|
legal: $legal,
|
|
|
|
|
code: $code,
|
|
|
|
|
brandCode: $brandCode,
|
2026-09-24 11:28:29 +02:00
|
|
|
createdBy: $createdBy,
|
|
|
|
|
gtin: $gtin,
|
2026-09-21 16:59:26 +02:00
|
|
|
updatedAt: $updatedAt,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-24 11:28:29 +02:00
|
|
|
/**
|
|
|
|
|
* @param array<int, CouponLegalInformation> $legal
|
|
|
|
|
*/
|
2026-09-21 16:59:26 +02:00
|
|
|
public static function hydrate(
|
|
|
|
|
CouponId $id,
|
|
|
|
|
CouponName $name,
|
|
|
|
|
bool $status,
|
|
|
|
|
CouponProductName $productName,
|
|
|
|
|
MoneyAmount $amount,
|
|
|
|
|
CouponPicture $picture,
|
|
|
|
|
CouponProduct $product,
|
|
|
|
|
CouponDiffusion $diffusion,
|
|
|
|
|
CouponAvailabilityCalendar $availability,
|
|
|
|
|
CouponValidity $validity,
|
2026-09-24 11:28:29 +02:00
|
|
|
array $legal,
|
2026-09-21 16:59:26 +02:00
|
|
|
ProcessingCode $code,
|
|
|
|
|
BrandCode $brandCode,
|
2026-09-24 11:28:29 +02:00
|
|
|
ActorId $createdBy,
|
|
|
|
|
?GS1 $gtin = null,
|
2026-09-21 16:59:26 +02:00
|
|
|
?\DateTimeInterface $updatedAt = null,
|
|
|
|
|
): self {
|
|
|
|
|
return new self(
|
|
|
|
|
id: $id,
|
|
|
|
|
name: $name,
|
|
|
|
|
status: $status,
|
|
|
|
|
productName: $productName,
|
|
|
|
|
amount: $amount,
|
|
|
|
|
picture: $picture,
|
|
|
|
|
product: $product,
|
|
|
|
|
diffusion: $diffusion,
|
|
|
|
|
availability: $availability,
|
|
|
|
|
validity: $validity,
|
|
|
|
|
legal: $legal,
|
|
|
|
|
code: $code,
|
|
|
|
|
brandCode: $brandCode,
|
2026-09-24 11:28:29 +02:00
|
|
|
createdBy: $createdBy,
|
|
|
|
|
gtin: $gtin,
|
2026-09-21 16:59:26 +02:00
|
|
|
updatedAt: $updatedAt,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|