TenantAtlas/apps/platform/app/Support/Operations/Actionability/OperationRunActionabilityResult.php
Ahmed Darrazi 0329cb5420
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 1m0s
feat: implement operation run actionability system
2026-06-08 15:19:55 +02:00

77 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support\Operations\Actionability;
use App\Models\OperationRun;
final readonly class OperationRunActionabilityResult
{
/**
* @param array<string, mixed> $metadata
*/
public function __construct(
public OperationRunActionabilityStatus $status,
public string $reasonCode,
public string $explanation,
public ?int $supersedingRunId = null,
public ?string $resolvingModelType = null,
public ?int $resolvingModelId = null,
public string $policyIdentifier = 'default',
public array $metadata = [],
public ?int $runId = null,
public ?string $operationType = null,
public ?string $canonicalType = null,
) {}
public function withRun(OperationRun $run): self
{
return new self(
status: $this->status,
reasonCode: $this->reasonCode,
explanation: $this->explanation,
supersedingRunId: $this->supersedingRunId,
resolvingModelType: $this->resolvingModelType,
resolvingModelId: $this->resolvingModelId,
policyIdentifier: $this->policyIdentifier,
metadata: $this->metadata,
runId: (int) $run->getKey(),
operationType: (string) $run->type,
canonicalType: $run->canonicalOperationType(),
);
}
public function requiresCurrentFollowUp(): bool
{
return $this->status->requiresCurrentFollowUp();
}
public function isActionable(): bool
{
return $this->requiresCurrentFollowUp();
}
/**
* @return array<string, mixed>
*/
public function toArray(): array
{
return [
'status' => $this->status->value,
'status_label' => $this->status->label(),
'actionable' => $this->requiresCurrentFollowUp(),
'reason_code' => $this->reasonCode,
'explanation' => $this->explanation,
'superseding_run_id' => $this->supersedingRunId,
'resolving_model_type' => $this->resolvingModelType,
'resolving_model_id' => $this->resolvingModelId,
'policy_identifier' => $this->policyIdentifier,
'metadata' => $this->metadata,
'run_id' => $this->runId,
'operation_type' => $this->operationType,
'canonical_type' => $this->canonicalType,
];
}
}