import { arg, defineCommand } from "politty";
import { z } from "zod";
import { readErpKitVersion } from "../../util";
import { executeCommand } from "../lib/command-result";
import { runVerify } from "./verify";

export const verifyCommand = defineCommand({
  name: "verify",
  description: "Run deterministic version and structure checks as a CI gate",
  args: z.object({
    modulesRoot: arg(z.string().default("modules"), {
      alias: "m",
      description: "Path to the modules directory",
    }),
    appsRoot: arg(z.string().default("apps"), {
      alias: "a",
      description: "Path to the apps directory (each child is one app)",
    }),
  }),
  run: (args) => {
    return executeCommand(() =>
      runVerify({
        modulesRoot: args.modulesRoot,
        appsRoot: args.appsRoot,
        cwd: process.cwd(),
        installedVersion: readErpKitVersion(),
      }),
    );
  },
});
