<?php
declare(strict_types=1);
namespace App\Domain\PaymentNotification\Model;
use App\Domain\Payment\Model\Payment;
use App\Domain\Payment\Model\PaymentStatus;
use App\Domain\PaymentNotification\Event\PaymentNotificationCreatedEvent;
use App\Domain\Shared\Model\Aggregate;
use App\Domain\Shared\Model\TimestampTrait;
use Symfony\Component\Uid\Uuid;
class PaymentNotification extends Aggregate
{
use TimestampTrait;
private int $attempts;
private PaymentStatus $paymentStatus;
public function __construct(
private readonly Uuid $id,
private readonly Payment $payment,
private bool $resolved,
private \DateTimeImmutable $sendDate
) {
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = null;
$this->attempts = 0;
$this->paymentStatus = $this->payment->getStatus();
$this->raise(new PaymentNotificationCreatedEvent($this));
}
public function getId(): Uuid
{
return $this->id;
}
public function getPayment(): Payment
{
return $this->payment;
}
public function getSendDate(): \DateTimeImmutable
{
return $this->sendDate;
}
public function setSendDate(\DateTimeImmutable $sendDate): void
{
$this->sendDate = $sendDate;
$this->updatedAt = new \DateTimeImmutable();
}
public function resolve(): void
{
$this->resolved = true;
$this->payment->setResolvedBySite(true);
$this->updatedAt = new \DateTimeImmutable();
}
public function getPaymentStatus(): PaymentStatus
{
return $this->paymentStatus;
}
public function isResolved(): bool
{
return $this->resolved;
}
public function incrementAttempts(): void
{
++$this->attempts;
$this->updatedAt = new \DateTimeImmutable();
}
public function getAttempts(): int
{
return $this->attempts;
}
}