TenantAtlas/apps/platform/app/Models/ReviewPublicationResolutionStep.php
Ahmed Darrazi 5c02afcae8
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 6m16s
feat: implement ReviewPublicationResolutionWorkflow (Spec 386)
2026-06-18 22:57:10 +02:00

84 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Support\ReviewPublicationResolution\ReviewPublicationResolutionStepKey;
use App\Support\ReviewPublicationResolution\ReviewPublicationResolutionStepStatus;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ReviewPublicationResolutionStep extends Model
{
protected $guarded = [];
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'summary' => 'array',
'metadata' => 'array',
'position' => 'integer',
'started_at' => 'datetime',
'completed_at' => 'datetime',
'failed_at' => 'datetime',
'superseded_at' => 'datetime',
];
}
/**
* @return BelongsTo<ReviewPublicationResolutionCase, $this>
*/
public function case(): BelongsTo
{
return $this->belongsTo(ReviewPublicationResolutionCase::class, 'case_id');
}
/**
* @return BelongsTo<OperationRun, $this>
*/
public function operationRun(): BelongsTo
{
return $this->belongsTo(OperationRun::class);
}
public function statusEnum(): ReviewPublicationResolutionStepStatus
{
return ReviewPublicationResolutionStepStatus::tryFrom((string) $this->status)
?? ReviewPublicationResolutionStepStatus::Pending;
}
public function stepKeyEnum(): ?ReviewPublicationResolutionStepKey
{
return ReviewPublicationResolutionStepKey::tryFrom((string) $this->step_key);
}
/**
* @return array{type:string,id:int}|null
*/
public function proofReference(): ?array
{
if (! is_string($this->proof_type) || $this->proof_type === '' || ! is_numeric($this->proof_id)) {
return null;
}
return [
'type' => $this->proof_type,
'id' => (int) $this->proof_id,
];
}
/**
* @param Builder<self> $query
* @return Builder<self>
*/
public function scopeOrdered(Builder $query): Builder
{
return $query->orderBy('position')->orderBy('id');
}
}