Files
2026-11-26 16:01:59 +02:00

55 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Catalog\Domain\Entities;
use App\Modules\Catalog\Domain\Exceptions\SharedUnitCannotUseStock;
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
/**
* A service unit (palveluyksikkö), e.g. Mediatuotanto. The shared unit
* ("Kaikille yhteiset") holds work types offered in every unit and has no
* services. A unit may use stock and machines (varaston ja koneiden
* käyttö); the shared unit follows the job's units instead.
*/
final class ServiceUnit extends CatalogItem
{
private function __construct(?int $id, CatalogName $name, private bool $shared, bool $active, int $sortOrder, private bool $usesStock)
{
parent::__construct($id, $name, $active, $sortOrder);
}
public static function create(CatalogName $name, int $sortOrder, bool $shared = false): self
{
return new self(null, $name, $shared, true, $sortOrder, false);
}
public static function reconstitute(int $id, CatalogName $name, bool $shared, bool $active, int $sortOrder, bool $usesStock = false): self
{
return new self($id, $name, $shared, $active, $sortOrder, $usesStock);
}
public function isShared(): bool
{
return $this->shared;
}
public function usesStock(): bool
{
return $this->usesStock;
}
/**
* @throws SharedUnitCannotUseStock
*/
public function useStock(bool $usesStock): void
{
if ($usesStock && $this->shared) {
throw new SharedUnitCannotUseStock;
}
$this->usesStock = $usesStock;
}
}