77 lines
2.0 KiB
PHP
77 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Enums;
|
|
|
|
use App\Jobs\PricelistPreProcessJob;
|
|
use App\Jobs\PricelistValidationJob;
|
|
use App\Jobs\PricelistExecutionJob;
|
|
|
|
enum PricelistWorkflowStep: string
|
|
{
|
|
case Preprocessing = 'preprocess';
|
|
case Validation = 'validation';
|
|
case Approval = 'approval';
|
|
case Execution = 'execution';
|
|
|
|
/**
|
|
* Magyar megnevezés (UI megjelenítéshez)
|
|
*/
|
|
public function label(): string
|
|
{
|
|
return match($this) {
|
|
self::Preprocessing => 'Előfeldolgozás',
|
|
self::Validation => 'Validálás',
|
|
self::Approval => 'Jóváhagyás',
|
|
self::Execution => 'Végrehajtás',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* A lépéshez tartozó Job osztály neve
|
|
*/
|
|
public function jobClass(): ?string
|
|
{
|
|
return match($this) {
|
|
self::Preprocessing => PricelistPreProcessJob::class,
|
|
self::Validation => PricelistValidationJob::class,
|
|
self::Execution => PricelistExecutionJob::class,
|
|
self::Approval => null, // Manuális lépésnél nincs automatikus job
|
|
};
|
|
}
|
|
|
|
/**
|
|
* A lépéshez tartozó Job példány visszaadása
|
|
*/
|
|
public function getJob(\App\Models\PricelistFile $file): ?object
|
|
{
|
|
$jobClass = $this->jobClass();
|
|
return $jobClass ? new $jobClass($file) : null;
|
|
}
|
|
|
|
/**
|
|
* Státusz színek (UI megjelenítéshez)
|
|
*/
|
|
public function color(string $status): string
|
|
{
|
|
return match ($status) {
|
|
'pending' => 'gray',
|
|
'inprogress' => 'primary',
|
|
'completed' => 'success',
|
|
'failed' => 'danger',
|
|
default => 'gray',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Segédfüggvény az alapértelmezett workflow struktúra legenerálásához
|
|
*/
|
|
public static function defaultSteps(): array
|
|
{
|
|
return array_map(fn($step) => [
|
|
'name' => $step->value,
|
|
'label' => $step->label(),
|
|
'status' => 'pending',
|
|
], self::cases());
|
|
}
|
|
}
|