62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Domain\Models\Entities;
|
||
|
|
|
||
|
|
use Domain\Models\ValueObjects\ProcessingCode;
|
||
|
|
use Domain\Models\ValueObjects\Stock\StockAdjustment;
|
||
|
|
use Domain\Models\ValueObjects\Stock\StockAmount;
|
||
|
|
use Domain\Models\ValueObjects\Stock\StockId;
|
||
|
|
use Shared\DDD\Models\AggregateRoot;
|
||
|
|
use Shared\DDD\Models\HasTimestampIdentifier;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @implements \Shared\DDD\Models\AggregateRoot<\Domain\Models\ValueObjects\Stock\StockId>
|
||
|
|
*/
|
||
|
|
final readonly class Stock implements AggregateRoot, HasTimestampIdentifier
|
||
|
|
{
|
||
|
|
private function __construct(
|
||
|
|
public StockId $id,
|
||
|
|
public StockAmount $stockAmount,
|
||
|
|
public StockAdjustment $stockAdjustment,
|
||
|
|
public CampaignCode $campaignCode,
|
||
|
|
public ProcessingCode $processingCode,
|
||
|
|
public ?\DateTimeInterface $updatedAt = null,
|
||
|
|
) {
|
||
|
|
}
|
||
|
|
|
||
|
|
public function id(): StockId
|
||
|
|
{
|
||
|
|
return $this->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function createdAt(): \DateTimeInterface
|
||
|
|
{
|
||
|
|
return $this->id->toDateTime();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function updatedAt(): ?\DateTimeInterface
|
||
|
|
{
|
||
|
|
return $this->updatedAt;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function hydrate(
|
||
|
|
StockId $id,
|
||
|
|
StockAmount $stockAmount,
|
||
|
|
StockAdjustment $stockAdjustment,
|
||
|
|
CampaignCode $campaignCode,
|
||
|
|
ProcessingCode $processingCode,
|
||
|
|
?\DateTimeInterface $updatedAt = null,
|
||
|
|
): self {
|
||
|
|
return new self(
|
||
|
|
id: $id,
|
||
|
|
stockAmount: $stockAmount,
|
||
|
|
stockAdjustment: $stockAdjustment,
|
||
|
|
campaignCode: $campaignCode,
|
||
|
|
processingCode: $processingCode,
|
||
|
|
updatedAt: $updatedAt,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|