85 lines
2.8 KiB
PHP
85 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domain\Models\Entities;
|
|
|
|
use Domain\Enums\Campaign\CampaignStatus;
|
|
use Domain\Enums\Campaign\CampaignType;
|
|
use Domain\Enums\Country;
|
|
use Domain\Models\ValueObjects\Brand\BrandCode;
|
|
use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId;
|
|
use Domain\Models\ValueObjects\CampaignRequest\Applicant;
|
|
use Domain\Models\ValueObjects\CampaignRequest\RejectionReason;
|
|
use Domain\Models\ValueObjects\PrintRules;
|
|
use Shared\DDD\Models\AggregateRoot;
|
|
use Shared\DDD\Models\HasTimestampIdentifier;
|
|
|
|
/**
|
|
* @implements \Shared\DDD\Models\AggregateRoot<\Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId>
|
|
*/
|
|
final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdentifier
|
|
{
|
|
private function __construct(
|
|
public CampaignRequestId $id,
|
|
public BrandCode $code,
|
|
public Applicant $applicant,
|
|
public Country $country,
|
|
public CampaignType $campaignType,
|
|
public ?PrintRules $printRules,
|
|
public RequestedCoupon $requestedCoupon,
|
|
public CampaignStatus $status,
|
|
public ?RejectionReason $rejectionReason = null,
|
|
public ?\DateTimeInterface $updatedAt = null,
|
|
) {
|
|
if ($this->status === CampaignStatus::REJECTED && ! $this->rejectionReason instanceof RejectionReason) {
|
|
throw new \DomainException('A rejection reason is required when the campaign request is rejected.');
|
|
}
|
|
|
|
if ($this->status !== CampaignStatus::REJECTED && $this->rejectionReason instanceof RejectionReason) {
|
|
throw new \DomainException('A rejection reason can only be set when the campaign request is rejected.');
|
|
}
|
|
}
|
|
|
|
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(
|
|
CampaignRequestId $id,
|
|
BrandCode $code,
|
|
Applicant $applicant,
|
|
Country $country,
|
|
CampaignType $campaignType,
|
|
?PrintRules $printRules,
|
|
RequestedCoupon $requestedCoupon,
|
|
CampaignStatus $status,
|
|
?RejectionReason $rejectionReason = null,
|
|
?\DateTimeInterface $updatedAt = null,
|
|
): self {
|
|
return new self(
|
|
id: $id,
|
|
code: $code,
|
|
applicant: $applicant,
|
|
country: $country,
|
|
campaignType: $campaignType,
|
|
printRules: $printRules,
|
|
requestedCoupon: $requestedCoupon,
|
|
status: $status,
|
|
rejectionReason: $rejectionReason,
|
|
updatedAt: $updatedAt,
|
|
);
|
|
}
|
|
}
|