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

export const versionsCommand = defineCommand({
  name: "versions",
  description:
    "Check that workspace dependencies and installed skills match the running erp-kit version",
  args: z.object({
    appsRoot: arg(z.string().default("apps"), {
      alias: "a",
      description: "Path to an apps directory (scans each app's backend/frontend package.json)",
    }),
    modulesRoot: arg(z.string().default("modules"), {
      alias: "m",
      description: "Path to a modules directory (scans each module's package.json)",
    }),
  }),
  run: (args) => {
    return executeCommand(() =>
      runInternalMeasureVersions({
        appsRoot: args.appsRoot,
        modulesRoot: args.modulesRoot,
        cwd: process.cwd(),
        installedVersion: readErpKitVersion(),
      }),
    );
  },
});
