*/ public function handle(int $workspaceId, ?string $status = null, bool $includeArchived = false): Collection { if ($status !== null) { $valid = ['draft', 'active', 'paused', 'completed', 'archived']; if (! in_array($status, $valid, true)) { throw new \InvalidArgumentException( sprintf('status must be one of: %s', implode(', ', $valid)) ); } } $query = AgentPlan::with('agentPhases') ->forWorkspace($workspaceId) ->orderBy('updated_at', 'desc'); if (! $includeArchived && $status !== 'archived') { $query->notArchived(); } if ($status !== null) { $query->where('status', $status); } return $query->get(); } }