'array', 'model_config' => 'array', 'is_active' => 'boolean', ]; /** * Get the version history for this prompt. */ public function versions(): HasMany { return $this->hasMany(PromptVersion::class)->orderByDesc('version'); } /** * Get the content tasks using this prompt. */ public function tasks(): HasMany { return $this->hasMany(ContentTask::class); } /** * Create a new version snapshot before saving changes. */ public function createVersion(?int $userId = null): PromptVersion { $latestVersion = $this->versions()->max('version') ?? 0; return $this->versions()->create([ 'version' => $latestVersion + 1, 'system_prompt' => $this->system_prompt, 'user_template' => $this->user_template, 'variables' => $this->variables, 'created_by' => $userId, ]); } /** * Interpolate variables into the user template. */ public function interpolate(array $data): string { $template = $this->user_template; foreach ($data as $key => $value) { if (is_string($value)) { $template = str_replace("{{{$key}}}", $value, $template); } } return $template; } /** * Scope to only active prompts. */ public function scopeActive($query) { return $query->where('is_active', true); } /** * Scope by category. */ public function scopeCategory($query, string $category) { return $query->where('category', $category); } /** * Scope by model provider. */ public function scopeForModel($query, string $model) { return $query->where('model', $model); } }