import path from "node:path";
import { defineCommand, arg } from "politty";
import { z } from "zod";
import { executeCommand } from "../../../lib/command-result";
import { runModuleGenerateCode } from "./code";

export const codeCommand = defineCommand({
  name: "code",
  description: "Generate boilerplate, implementation stubs, and generated code from docs",
  args: z.object({
    path: arg(z.string(), {
      alias: "p",
      description: "Path to the module directory",
    }),
  }),
  run: (args) => {
    return executeCommand(() => {
      const modulePath = path.resolve(process.cwd(), args.path);
      const moduleName = path.basename(modulePath);
      console.log(`Generating code for ${moduleName}...`);
      return runModuleGenerateCode(modulePath, moduleName);
    });
  },
});
