const { contextBridge, ipcRenderer } = require("electron");

contextBridge.exposeInMainWorld("electronAPI", {
  // ✅ 运行 Python 脚本
  runPythonExe: async (args) => ipcRenderer.invoke("run-python-exe", args),
  callPythonAPI: (apiName, params) =>
    ipcRenderer.invoke("run-python-exe", apiName, params),

  // ✅ 发送 / 接收消息
  sendMessage: (message) => ipcRenderer.send("message", message),
  receiveMessage: (callback) => {
    ipcRenderer.on("response", (event, data) => callback(data));
  },

  // ✅ 文件操作
  getFilePath: () => ipcRenderer.invoke("get-file-path"),
  getInstallPath: () => ipcRenderer.invoke("get-install-path"),
  readCsv: (filePath) => ipcRenderer.invoke("read-csv", filePath),

  // ✅ 保存 / 读取 提交文件
  saveSubmission: (payload) => ipcRenderer.invoke("save-submission", payload),
  readTextFile: (filePath) => ipcRenderer.invoke("read-text-file", filePath),
  readJsonFile: (filePath) => ipcRenderer.invoke("read-json-file", filePath),

  // ✅ 打开文件夹（调用主进程 open-path）
  // 
    openPath: (filePath) => ipcRenderer.invoke("open-path", filePath),

  // ✅ 删除单个数据文件夹
  deleteFolder: (folderPath) => ipcRenderer.invoke("delete-folder", folderPath),

  // ✅ 清空所有数据文件夹
  clearAllFolders: () => ipcRenderer.invoke("clear-all-folders"),
});
