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

const allowedRepairActions = new Set([
  'cleanup-caches',
  'open-storage-settings',
  'open-software-update',
  'open-security-settings',
  'fix-security-baseline',
  'open-firewall-settings',
  'open-encryption-settings',
  'open-antivirus-settings',
  'flush-dns',
  'deactivate-once-off-session'
]);

contextBridge.exposeInMainWorld('oncallDesktop', {
  platform: process.platform,
  arch: process.arch,
  wrapper: 'electron',
  version: '0.3.8-bridge-connectivity-rc1',
  localScannerPort: 37879,
  getBridgeStatus: () => ipcRenderer.invoke('device:bridge-status'),
  runHealthScan: () => ipcRenderer.invoke('device:health-scan'),
  runRepairAction: (action) => {
    const requested = String(action || '');
    if (!allowedRepairActions.has(requested)) {
      return Promise.resolve({ ok: false, action: requested, error: 'Unsupported or blocked repair action.' });
    }
    return ipcRenderer.invoke('device:repair-action', requested);
  }
});
