2026-09-22 13:01:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Domain\Models\Entities;
|
|
|
|
|
|
2026-09-25 10:24:35 +02:00
|
|
|
use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestStatus;
|
|
|
|
|
use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestType;
|
2026-09-22 13:01:30 +02:00
|
|
|
use Domain\Models\ValueObjects\Brand\BrandCode;
|
|
|
|
|
use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId;
|
|
|
|
|
use Domain\Models\ValueObjects\CampaignRequest\Applicant;
|
2026-09-22 16:29:34 +02:00
|
|
|
use Domain\Models\ValueObjects\CampaignRequest\RejectionReason;
|
2026-09-25 10:24:35 +02:00
|
|
|
use Domain\Models\ValueObjects\CountryAuthorized;
|
2026-09-22 13:01:30 +02:00
|
|
|
use Domain\Models\ValueObjects\PrintRules;
|
2026-09-25 12:14:48 +02:00
|
|
|
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
|
2026-09-22 13:01:30 +02:00
|
|
|
use Shared\DDD\Models\AggregateRoot;
|
|
|
|
|
use Shared\DDD\Models\HasTimestampIdentifier;
|
2026-09-23 11:34:44 +02:00
|
|
|
use Shared\Helpers\DatesHelper;
|
2026-09-22 13:01:30 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @implements \Shared\DDD\Models\AggregateRoot<\Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId>
|
|
|
|
|
*/
|
|
|
|
|
final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdentifier
|
|
|
|
|
{
|
|
|
|
|
private function __construct(
|
2026-09-23 09:24:18 +02:00
|
|
|
public CampaignRequestId $id,
|
|
|
|
|
public BrandCode $code,
|
|
|
|
|
public Applicant $applicant,
|
2026-09-25 10:24:35 +02:00
|
|
|
public CountryAuthorized $country,
|
|
|
|
|
public CampaignRequestType $campaignType,
|
2026-09-23 09:24:18 +02:00
|
|
|
public ?PrintRules $printRules,
|
|
|
|
|
public RequestedCoupon $requestedCoupon,
|
2026-09-25 10:24:35 +02:00
|
|
|
public CampaignRequestStatus $status,
|
2026-09-23 09:24:18 +02:00
|
|
|
public ?RejectionReason $rejectionReason = null,
|
2026-09-22 13:01:30 +02:00
|
|
|
public ?\DateTimeInterface $updatedAt = null,
|
2026-09-22 16:29:34 +02:00
|
|
|
) {
|
2026-09-25 10:24:35 +02:00
|
|
|
if ($this->status === CampaignRequestStatus::REJECTED && ! $this->rejectionReason instanceof RejectionReason) {
|
2026-09-22 16:29:34 +02:00
|
|
|
throw new \DomainException('A rejection reason is required when the campaign request is rejected.');
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-25 10:24:35 +02:00
|
|
|
if ($this->status !== CampaignRequestStatus::REJECTED && $this->rejectionReason instanceof RejectionReason) {
|
2026-09-22 16:29:34 +02:00
|
|
|
throw new \DomainException('A rejection reason can only be set when the campaign request is rejected.');
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-22 13:01:30 +02:00
|
|
|
|
|
|
|
|
public function id(): CampaignRequestId
|
|
|
|
|
{
|
|
|
|
|
return $this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createdAt(): \DateTimeInterface
|
|
|
|
|
{
|
|
|
|
|
return $this->id->toDateTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updatedAt(): ?\DateTimeInterface
|
|
|
|
|
{
|
|
|
|
|
return $this->updatedAt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function hydrate(
|
2026-09-23 09:24:18 +02:00
|
|
|
CampaignRequestId $id,
|
|
|
|
|
BrandCode $code,
|
|
|
|
|
Applicant $applicant,
|
2026-09-25 10:24:35 +02:00
|
|
|
CountryAuthorized $country,
|
|
|
|
|
CampaignRequestType $campaignType,
|
2026-09-23 09:24:18 +02:00
|
|
|
?PrintRules $printRules,
|
|
|
|
|
RequestedCoupon $requestedCoupon,
|
2026-09-25 10:24:35 +02:00
|
|
|
CampaignRequestStatus $status,
|
2026-09-23 09:24:18 +02:00
|
|
|
?RejectionReason $rejectionReason = null,
|
2026-09-22 13:01:30 +02:00
|
|
|
?\DateTimeInterface $updatedAt = null,
|
|
|
|
|
): self {
|
|
|
|
|
return new self(
|
|
|
|
|
id: $id,
|
|
|
|
|
code: $code,
|
|
|
|
|
applicant: $applicant,
|
|
|
|
|
country: $country,
|
|
|
|
|
campaignType: $campaignType,
|
|
|
|
|
printRules: $printRules,
|
|
|
|
|
requestedCoupon: $requestedCoupon,
|
|
|
|
|
status: $status,
|
2026-09-22 16:29:34 +02:00
|
|
|
rejectionReason: $rejectionReason,
|
2026-09-22 13:01:30 +02:00
|
|
|
updatedAt: $updatedAt,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-09-23 11:34:44 +02:00
|
|
|
|
|
|
|
|
public function reject(RejectionReason $reason): self
|
|
|
|
|
{
|
2026-09-25 10:24:35 +02:00
|
|
|
if ($this->status !== CampaignRequestStatus::CREATED) {
|
2026-09-23 11:34:44 +02:00
|
|
|
throw new \DomainException('Only a created campaign request can be rejected.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new self(
|
|
|
|
|
id: $this->id,
|
|
|
|
|
code: $this->code,
|
|
|
|
|
applicant: $this->applicant,
|
|
|
|
|
country: $this->country,
|
|
|
|
|
campaignType: $this->campaignType,
|
|
|
|
|
printRules: $this->printRules,
|
|
|
|
|
requestedCoupon: $this->requestedCoupon,
|
2026-09-25 10:24:35 +02:00
|
|
|
status: CampaignRequestStatus::REJECTED,
|
2026-09-23 11:34:44 +02:00
|
|
|
rejectionReason: $reason,
|
|
|
|
|
updatedAt: DatesHelper::now(),
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-09-28 14:32:19 +02:00
|
|
|
|
|
|
|
|
public function rejectionReason(): RejectionReason
|
|
|
|
|
{
|
|
|
|
|
if (! $this->rejectionReason instanceof RejectionReason) {
|
|
|
|
|
throw new \DomainException('Only a rejected campaign request has a rejection reason.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->rejectionReason;
|
|
|
|
|
}
|
2026-09-22 13:01:30 +02:00
|
|
|
}
|