Files
Toiminnanohjaus/app/Modules/Inventory/Application/UseCases/SetStockItemActive.php
T
2026-11-26 16:18:59 +02:00

34 lines
962 B
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\UseCases;
use App\Modules\Inventory\Domain\Contracts\StockItemRepository;
use App\Modules\Inventory\Domain\Exceptions\StockItemNotFound;
use App\Modules\Shared\Application\Contracts\TransactionManager;
/**
* Takes a stock item out of use, or back. An item out of use cannot be
* used, but its movements stay.
*/
final class SetStockItemActive
{
public function __construct(
private StockItemRepository $items,
private TransactionManager $transactions,
) {}
/**
* @throws StockItemNotFound
*/
public function execute(int $itemId, bool $active): void
{
$this->transactions->run(function () use ($itemId, $active): void {
$item = $this->items->findById($itemId) ?? throw new StockItemNotFound;
$active ? $item->activate() : $item->deactivate();
$this->items->save($item);
});
}
}