import { defineCommand, arg } from "politty";
import { z } from "zod";
import { executeCommand } from "../../lib/command-result";
import { runDocSearch } from "./search";

export const searchCommand = defineCommand({
  name: "search",
  description: "Search across all module documentation",
  args: z.object({
    query: arg(z.string(), {
      positional: true,
      description: "Search query",
    }),
    type: arg(z.string().optional(), {
      alias: "t",
      description: "Filter by doc type (command, query, model, feature, readme)",
    }),
    format: arg(z.enum(["text", "json"]).default("text"), {
      alias: "f",
      description: "Output format (text or json)",
    }),
  }),
  run: (args) => {
    return executeCommand(() => runDocSearch(args.query, args.type, args.format));
  },
});
