// @ts-nocheck
import fs from "node:fs";
import { info, warn } from "../lib/log.ts";

const steps = [
  {
    id: "load-context",
    title: "Load workbook and local configuration",
    status: "planned",
  },
  {
    id: "load-manufacturer",
    title: "Load selected manufacturer and products to process",
    status: "needs-mapping",
  },
  {
    id: "check-stock",
    title: "Check supplier stock and existing catalog combinations",
    status: "needs-mapping",
  },
  {
    id: "build-combinations",
    title: "Create or update product combinations",
    status: "needs-mapping",
  },
  {
    id: "update-prices",
    title: "Update product and combination prices",
    status: "needs-mapping",
  },
  {
    id: "update-texts",
    title: "Generate/update product card texts",
    status: "needs-mapping",
  },
  {
    id: "handle-pictures",
    title: "Resolve cover/detail product pictures",
    status: "needs-mapping",
  },
];

export async function runCatalogMaker({ config }) {
  info("Catalog maker workflow");
  info(`Mode: ${config.dryRun ? "dry-run" : "live"}`);
  info(`Workbook: ${config.sourceWorkbook}`);

  if (!fs.existsSync(config.sourceWorkbook)) {
    throw new Error(`Source workbook not found: ${config.sourceWorkbook}`);
  }

  info("");
  info("Planned replacement for Excel button: Catalog maker - 20");

  for (const step of steps) {
    const marker = step.status === "planned" ? "ready" : step.status;
    info(`- ${step.id}: ${marker} - ${step.title}`);
  }

  warn("");
  warn("No database or catalog changes were made. Database access in this project is read-only by rule #1.");
  warn("Next step: map the original VBA/SQL behavior for CommandButton20_Click.");
}
