Add machines with day-by-day work lists for job tasks

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:43:55 +02:00
co-authored by Claude Sonnet 5.5
parent 0de0e332b2
commit aac579257a
59 changed files with 3803 additions and 1 deletions
@@ -0,0 +1,162 @@
<?php
declare(strict_types=1);
namespace App\Modules\Machines\Domain\Entities;
use App\Modules\Machines\Domain\Enums\MachineType;
use App\Modules\Machines\Domain\Exceptions\MachineInactive;
use App\Modules\Machines\Domain\Exceptions\MachineNeedsServiceUnit;
use App\Modules\Machines\Domain\ValueObjects\MachineCounter;
use App\Modules\Machines\Domain\ValueObjects\MachineName;
/**
* A machine (kone, spec 19.4): a printing press, a sticker cutter or other,
* in one or more service units, with a responsible person who gets the
* maintenance notifications, and counters. Machines are never deleted: one
* out of use is not offered, but its history stays.
*/
final class Machine
{
/**
* @param list<int> $serviceUnitIds
* @param list<MachineCounter> $counters
*/
private function __construct(
private ?int $id,
private MachineName $name,
private MachineType $type,
private ?string $description,
private array $serviceUnitIds,
private ?int $responsibleUserId,
private array $counters,
private bool $active,
) {
if ($serviceUnitIds === []) {
throw new MachineNeedsServiceUnit;
}
}
/**
* @param list<int> $serviceUnitIds
* @param list<MachineCounter> $counters
*
* @throws MachineNeedsServiceUnit
*/
public static function create(MachineName $name, MachineType $type, ?string $description, array $serviceUnitIds, ?int $responsibleUserId, array $counters): self
{
return new self(null, $name, $type, self::text($description), array_values(array_unique($serviceUnitIds)), $responsibleUserId, $counters, true);
}
/**
* @param list<int> $serviceUnitIds
* @param list<MachineCounter> $counters
*/
public static function reconstitute(int $id, MachineName $name, MachineType $type, ?string $description, array $serviceUnitIds, ?int $responsibleUserId, array $counters, bool $active): self
{
return new self($id, $name, $type, $description, $serviceUnitIds, $responsibleUserId, $counters, $active);
}
/**
* @param list<int> $serviceUnitIds
* @param list<MachineCounter> $counters
*
* @throws MachineNeedsServiceUnit
*/
public function change(MachineName $name, MachineType $type, ?string $description, array $serviceUnitIds, ?int $responsibleUserId, array $counters): void
{
if ($serviceUnitIds === []) {
throw new MachineNeedsServiceUnit;
}
$this->name = $name;
$this->type = $type;
$this->description = self::text($description);
$this->serviceUnitIds = array_values(array_unique($serviceUnitIds));
$this->responsibleUserId = $responsibleUserId;
$this->counters = $counters;
}
/**
* Whether the machine serves any of the service units.
*
* @param list<int> $serviceUnitIds
*/
public function servesAnyOf(array $serviceUnitIds): bool
{
return array_intersect($this->serviceUnitIds, $serviceUnitIds) !== [];
}
/**
* @throws MachineInactive
*/
public function ensureActive(): void
{
if (! $this->active) {
throw new MachineInactive;
}
}
public function activate(): void
{
$this->active = true;
}
public function deactivate(): void
{
$this->active = false;
}
public function id(): ?int
{
return $this->id;
}
public function name(): MachineName
{
return $this->name;
}
public function type(): MachineType
{
return $this->type;
}
public function description(): ?string
{
return $this->description;
}
/**
* @return list<int>
*/
public function serviceUnitIds(): array
{
return $this->serviceUnitIds;
}
public function responsibleUserId(): ?int
{
return $this->responsibleUserId;
}
/**
* @return list<MachineCounter>
*/
public function counters(): array
{
return $this->counters;
}
public function isActive(): bool
{
return $this->active;
}
private static function text(?string $value): ?string
{
$value = $value === null ? '' : trim($value);
return $value === '' ? null : mb_substr($value, 0, 5000);
}
}