feat: bootstrap JOBcard CRM foundation
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Domain\Jobcard;
|
||||
|
||||
final class StatusTransitionValidator
|
||||
{
|
||||
public const STATUSES = ['new', 'assigned', 'in_progress', 'awaiting_client', 'awaiting_parts', 'completed', 'closed'];
|
||||
|
||||
private const TRANSITIONS = [
|
||||
'new' => ['assigned'],
|
||||
'assigned' => ['in_progress'],
|
||||
'in_progress' => ['awaiting_client', 'awaiting_parts', 'completed'],
|
||||
'awaiting_client' => ['in_progress', 'completed'],
|
||||
'awaiting_parts' => ['in_progress', 'completed'],
|
||||
'completed' => ['closed'],
|
||||
'closed' => [],
|
||||
];
|
||||
|
||||
public function canTransition(string $from, string $to): bool
|
||||
{
|
||||
return in_array($from, self::STATUSES, true)
|
||||
&& in_array($to, self::STATUSES, true)
|
||||
&& ($from === $to || in_array($to, self::TRANSITIONS[$from], true));
|
||||
}
|
||||
|
||||
public function allowedFrom(string $from): array
|
||||
{
|
||||
return in_array($from, self::STATUSES, true) ? array_merge([$from], self::TRANSITIONS[$from]) : [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user