// AGENT 破甲 - preload (sandboxed)
const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('agent', {
  version: () => ipcRenderer.invoke('app:version'),
  license: {
    status: () => ipcRenderer.invoke('license:status'),
    activate: (token) => ipcRenderer.invoke('license:activate', token),
    deactivate: () => ipcRenderer.invoke('license:deactivate')
  },
  skills: {
    list: () => ipcRenderer.invoke('skills:list'),
    targets: () => ipcRenderer.invoke('skills:targets'),
    install: (target, names) => ipcRenderer.invoke('skills:install', target, names),
    uninstall: (target, names) => ipcRenderer.invoke('skills:uninstall', target, names)
  },
  log: {
    list: () => ipcRenderer.invoke('log:list'),
    onAppend: (cb) => {
      const listener = (_e, line) => cb(line);
      ipcRenderer.on('log:append', listener);
      return () => ipcRenderer.removeListener('log:append', listener);
    }
  },
  update: {
    check: () => ipcRenderer.invoke('update:check'),
    download: (url, sha512) => ipcRenderer.invoke('update:download', url, sha512)
  },
  openExternal: (url) => ipcRenderer.invoke('app:openExternal', url)
});
