'integer', 'max_attempts' => 'integer', 'started_at' => 'datetime', 'completed_at' => 'datetime', 'provisioning_log' => 'array', ]; public function order(): BelongsTo { return $this->belongsTo(CustomerHostingOrder::class, 'customer_hosting_order_id'); } public function scopeQueued($query) { return $query->where('status', self::STATUS_QUEUED); } public function scopeProcessing($query) { return $query->where('status', self::STATUS_PROCESSING); } public function scopeFailed($query) { return $query->where('status', self::STATUS_FAILED); } public function canRetry(): bool { return $this->status === self::STATUS_FAILED && $this->attempts < $this->max_attempts; } public function markAsProcessing(): void { $this->update([ 'status' => self::STATUS_PROCESSING, 'started_at' => now(), 'attempts' => $this->attempts + 1, ]); } public function markAsCompleted(): void { $this->update([ 'status' => self::STATUS_COMPLETED, 'completed_at' => now(), ]); } public function markAsFailed(string $error): void { $log = $this->provisioning_log ?? []; $log[] = [ 'timestamp' => now()->toIso8601String(), 'attempt' => $this->attempts, 'error' => $error, ]; $this->update([ 'status' => self::STATUS_FAILED, 'error_message' => $error, 'provisioning_log' => $log, ]); } public function addLog(string $message, string $level = 'info'): void { $log = $this->provisioning_log ?? []; $log[] = [ 'timestamp' => now()->toIso8601String(), 'level' => $level, 'message' => $message, ]; $this->update(['provisioning_log' => $log]); } }