import fs from "node:fs";
import path from "node:path";

const root = process.cwd();
const viewPath = path.join(root, "src/views/InventoryLedgerView.vue");
const dictionariesPath = path.join(root, "src/utils/dictionaries.js");

const view = fs.readFileSync(viewPath, "utf8");
const dictionaries = fs.readFileSync(dictionariesPath, "utf8");

const checks = [
  ["raw return operation button", view.includes("raw-return-out") && view.includes("退货出库")],
  ["dedicated raw return drawer", view.includes("rawReturnDrawerOpen") && view.includes("原材料退货出库")],
  ["purchase links endpoint", view.includes("/inventory/stock-lots/") && view.includes("/purchase-links")],
  ["return outbound endpoint", view.includes("/inventory/raw-material-return-outbound")],
  ["available weight subtracts locked weight", view.includes("rawReturnLotAvailableWeight") && view.includes("locked_weight_kg")],
  ["purchase link stale request guard", view.includes("rawReturnLinksRequestSeq") && view.includes("requestSeq !== rawReturnLinksRequestSeq")],
  ["lot change clears logistics evidence", view.includes("rawReturnForm.waybill_no = \"\"") && view.includes("rawReturnForm.order_photo_url = \"\"")],
  ["purchase return label", dictionaries.includes("PURCHASE_RETURN_OUT") && dictionaries.includes("采购退货出库")],
];

const failed = checks.filter(([, passed]) => !passed);
if (failed.length) {
  console.error("Raw return UI checks failed:");
  failed.forEach(([name]) => console.error(`- ${name}`));
  process.exit(1);
}

console.log("Raw return UI checks passed");
