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

contextBridge.exposeInMainWorld('orgBoardDesktop', {
  isDesktop: true,
  async getSystemStatus() {
    return ipcRenderer.invoke('desktop:getSystemStatus');
  },
  async getAppVersion() {
    return ipcRenderer.invoke('desktop:getAppVersion');
  },
  async openOllamaInstaller() {
    return ipcRenderer.invoke('desktop:openOllamaInstaller');
  },
  async startOllama() {
    return ipcRenderer.invoke('desktop:startOllama');
  },
  async pullOllamaModel(model) {
    return ipcRenderer.invoke('desktop:pullOllamaModel', model);
  },
  async getUpdateStatus() {
    return ipcRenderer.invoke('desktop:getUpdateStatus');
  },
  async checkForUpdates() {
    return ipcRenderer.invoke('desktop:checkForUpdates');
  },
  async openExternal(url) {
    return ipcRenderer.invoke('desktop:openExternal', url);
  },
  async getPendingAuthCallback() {
    return ipcRenderer.invoke('desktop:getPendingAuthCallback');
  },
  onAuthCallback(listener) {
    const handler = (_event, payload) => listener(payload);
    ipcRenderer.on('desktop:auth-callback', handler);
    return () => ipcRenderer.removeListener('desktop:auth-callback', handler);
  },
  onUpdateStatus(listener) {
    const handler = (_event, payload) => listener(payload);
    ipcRenderer.on('desktop:update-status', handler);
    return () => ipcRenderer.removeListener('desktop:update-status', handler);
  }
});
