*/ 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, ); } }