72 lines
1.5 KiB
PHP
72 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Inventory\Domain\Entities;
|
|
|
|
use App\Modules\Inventory\Domain\ValueObjects\StockName;
|
|
|
|
/**
|
|
* A group of stock items (nimikeryhmä), e.g. Paperit ja kartongit. Groups
|
|
* are ordered, and never deleted, only taken out of use.
|
|
*/
|
|
final class StockItemGroup
|
|
{
|
|
private function __construct(
|
|
private ?int $id,
|
|
private StockName $name,
|
|
private int $sortOrder,
|
|
private bool $active,
|
|
) {}
|
|
|
|
public static function create(StockName $name, int $sortOrder): self
|
|
{
|
|
return new self(null, $name, $sortOrder, true);
|
|
}
|
|
|
|
public static function reconstitute(int $id, StockName $name, int $sortOrder, bool $active): self
|
|
{
|
|
return new self($id, $name, $sortOrder, $active);
|
|
}
|
|
|
|
public function rename(StockName $name): void
|
|
{
|
|
$this->name = $name;
|
|
}
|
|
|
|
public function activate(): void
|
|
{
|
|
$this->active = true;
|
|
}
|
|
|
|
public function deactivate(): void
|
|
{
|
|
$this->active = false;
|
|
}
|
|
|
|
public function swapOrderWith(self $other): void
|
|
{
|
|
[$this->sortOrder, $other->sortOrder] = [$other->sortOrder, $this->sortOrder];
|
|
}
|
|
|
|
public function id(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function name(): StockName
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function sortOrder(): int
|
|
{
|
|
return $this->sortOrder;
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return $this->active;
|
|
}
|
|
}
|