import { readFileSync } from "node:fs";

const inventory = readFileSync(new URL("../src/views/InventoryLedgerView.vue", import.meta.url), "utf8");
const dictionaries = readFileSync(new URL("../src/utils/dictionaries.js", import.meta.url), "utf8");

const requiredInventorySnippets = [
  "REWORK_FINISHED_IN",
  "返工入库",
  "reworkCompletion",
  "REWORK_SCRAP_IN",
  "返工废料入库",
  "reworkScrapInbound",
  "isReworkScrapInbound",
  "source_doc_type: isProductionScrapInbound.value || isReworkScrapInbound.value ? \"WORK_ORDER\"",
  "inbound_qty: inboundQty"
];

const requiredDictionarySnippets = [
  "REWORK_FINISHED_IN: \"返工入库\"",
  "REWORK_SCRAP_IN: \"返工废料入库\"",
  "REWORK_RECEIPT: \"返工入库\""
];

for (const snippet of requiredInventorySnippets) {
  if (!inventory.includes(snippet)) {
    throw new Error(`InventoryLedgerView.vue missing ${snippet}`);
  }
}

for (const snippet of requiredDictionarySnippets) {
  if (!dictionaries.includes(snippet)) {
    throw new Error(`dictionaries.js missing ${snippet}`);
  }
}

console.log("return rework closed-loop UI guard passed");
