import { z } from 'zod';
import { createCommand } from "../../../types.js";
import * as tui from "../../../tui.js";
import { createStorageAdapter } from "./util.js";
import { getCommand } from "../../../command-prefix.js";
const NamespaceListResponseSchema = z.array(z.string().describe('Namespace name'));
export const listNamespacesSubcommand = createCommand({
    name: 'list-namespaces',
    aliases: ['namespaces', 'ns'],
    description: 'List all vector namespaces',
    tags: ['read-only', 'fast', 'requires-auth'],
    requires: { auth: true, region: true },
    optional: { project: true },
    examples: [
        { command: getCommand('vector list-namespaces'), description: 'List all namespaces' },
        { command: getCommand('vector namespaces'), description: 'List namespaces (using alias)' },
        { command: getCommand('vector ns'), description: 'List namespaces (short alias)' },
    ],
    schema: {
        options: z.object({
            orgId: z.string().optional().describe('filter by organization id'),
        }),
        response: NamespaceListResponseSchema,
    },
    webUrl: '/services/vector',
    idempotent: true,
    async handler(ctx) {
        const { options, opts } = ctx;
        const storage = await createStorageAdapter(ctx, opts?.orgId);
        const namespaces = await storage.getNamespaces();
        if (!options.json) {
            if (namespaces.length === 0) {
                tui.info('No vector namespaces found');
            }
            else {
                tui.info(`Found ${namespaces.length} namespace(s):`);
                for (const name of namespaces) {
                    tui.arrow(name);
                }
            }
        }
        return namespaces;
    },
});
//# sourceMappingURL=list-namespaces.js.map