import { contextBridge, ipcRenderer } from 'electron' import { IPC_CHANNELS, type AvailabilityQuery, type CancelBookingInput, type CreateBookingInput, type CreateMonitorTaskInput, type TennisBookApi, type UpdateCourtSettingsInput } from '../shared/contracts' const api: TennisBookApi = { listCourts: () => ipcRenderer.invoke(IPC_CHANNELS.listCourts), getAvailability: (query: AvailabilityQuery) => ipcRenderer.invoke(IPC_CHANNELS.getAvailability, query), getCourtSettings: (courtId: string) => ipcRenderer.invoke(IPC_CHANNELS.getCourtSettings, courtId), updateCourtSettings: (input: UpdateCourtSettingsInput) => ipcRenderer.invoke(IPC_CHANNELS.updateCourtSettings, input), createBooking: (input: CreateBookingInput) => ipcRenderer.invoke(IPC_CHANNELS.createBooking, input), cancelBooking: (input: CancelBookingInput) => ipcRenderer.invoke(IPC_CHANNELS.cancelBooking, input), getPendingBooking: (courtId: string) => ipcRenderer.invoke(IPC_CHANNELS.getPendingBooking, courtId), listMonitorTasks: () => ipcRenderer.invoke(IPC_CHANNELS.listMonitorTasks), getMonitorTaskDetail: (taskId: string) => ipcRenderer.invoke(IPC_CHANNELS.getMonitorTaskDetail, taskId), createMonitorTask: (input: CreateMonitorTaskInput) => ipcRenderer.invoke(IPC_CHANNELS.createMonitorTask, input), setMonitorTaskEnabled: (taskId: string, enabled: boolean) => ipcRenderer.invoke(IPC_CHANNELS.setMonitorTaskEnabled, taskId, enabled), setMonitorTaskAutoBooking: (taskId: string, enabled: boolean) => ipcRenderer.invoke(IPC_CHANNELS.setMonitorTaskAutoBooking, taskId, enabled), deleteMonitorTask: (taskId: string) => ipcRenderer.invoke(IPC_CHANNELS.deleteMonitorTask, taskId), takeMonitorAlerts: () => ipcRenderer.invoke(IPC_CHANNELS.takeMonitorAlerts), listUnreadMonitorAlerts: () => ipcRenderer.invoke(IPC_CHANNELS.listUnreadMonitorAlerts), acknowledgeMonitorAlerts: (taskId?: string) => ipcRenderer.invoke(IPC_CHANNELS.acknowledgeMonitorAlerts, taskId), onMonitorAlert: (listener: () => void) => { const handler = () => listener() ipcRenderer.on(IPC_CHANNELS.monitorAlert, handler) return () => ipcRenderer.removeListener(IPC_CHANNELS.monitorAlert, handler) }, onShowMonitorTask: (listener: (taskId: string) => void) => { const handler = (_event: Electron.IpcRendererEvent, taskId: string) => listener(taskId) ipcRenderer.on(IPC_CHANNELS.showMonitorTask, handler) return () => ipcRenderer.removeListener(IPC_CHANNELS.showMonitorTask, handler) } } contextBridge.exposeInMainWorld('tennisBook', api)