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

// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld('electronAPI', {
  getDevices: (params) => ipcRenderer.invoke('api-get-devices', params),
  getAuthInfo: (params) => ipcRenderer.invoke('api-get-auth-info', params),

  // Camera proxy functionality
  launchCookieCameraProxy: (params) => ipcRenderer.invoke('camera-proxy-cookie-launch', params),
  stopCameraProxy: (processId) => ipcRenderer.invoke('camera-proxy-stop', { processId }),

  // Extension cookie bridge (push from main process)
  onExtensionCookie: (callback) => {
    ipcRenderer.on('extension-cookie-received', (event, data) => {
      try {
        callback(data);
      } catch (error) {
        console.error('Extension cookie handler error:', error);
      }
    });
  }
});