import { existsSync } from "node:fs";
import { rm } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const projectRoot = path.resolve(__dirname, "..");
const legacyProfileDirs = [
  path.join(projectRoot, "automation", ".browser"),
  path.join(projectRoot, "chatbot", ".browser"),
];

for (const dir of legacyProfileDirs) {
  if (!existsSync(dir)) {
    console.log(`[clear-legacy-1688-profiles] skip missing ${dir}`);
    continue;
  }

  await rm(dir, { recursive: true, force: true });
  console.log(`[clear-legacy-1688-profiles] removed ${dir}`);
}
