const { ipcMain } = require("electron");
//const Nucleus = require("nucleus-nodejs");
const ipcTypes = require("../../src/ipc.types.commonjs");
const { ImportJob } = require("../decoder/decoder");
const { GetListOfEstimates, DeleteAllEms } = require("./file-scan");

ipcMain.on(
  ipcTypes.default.fileScan.toMain.scanFilePaths,
  async (event, object) => {
    const ret = await GetListOfEstimates();
    event.reply(
      ipcTypes.default.fileScan.toRenderer.scanFilePathsResponse,
      ret
    );
  }
);

ipcMain.on(
  ipcTypes.default.fileScan.toMain.importJob,
  async (event, filePath) => {
  //  Nucleus.track("IMPORT_JOB_FROM_SCAN");
    await ImportJob(filePath);
  }
);

ipcMain.on(
  ipcTypes.default.fileScan.toMain.deleteAllEms,
  async (event, filePath) => {
 //   Nucleus.track("DELETE_ALLEMS");
    await DeleteAllEms();
    const ret = await GetListOfEstimates();
    event.reply(
      ipcTypes.default.fileScan.toRenderer.scanFilePathsResponse,
      ret
    );
  }
);
