import { ipcMain } from 'electron' import { IPC } from '../../../shared/ipc-channels' import type { BookMeta, CreateBookParams } from '../../../shared/types' import { BookRegistryService } from '../../services/book-registry' import { wrap } from '../result' export function registerBookHandlers(registry: BookRegistryService): void { ipcMain.handle(IPC.BOOK_LIST, () => wrap(() => registry.list())) ipcMain.handle(IPC.BOOK_CREATE, (_event, params: CreateBookParams) => wrap(() => registry.create(params)) ) ipcMain.handle(IPC.BOOK_DELETE, (_event, { bookId }: { bookId: string }) => wrap(() => { registry.delete(bookId) }) ) ipcMain.handle(IPC.BOOK_OPEN, (_event, { bookId }: { bookId: string }) => wrap(() => registry.open(bookId)) ) ipcMain.handle( IPC.BOOK_UPDATE_META, ( _event, { bookId, ...patch }: { bookId: string lastChapterId?: string | null lastOpenedAt?: string status?: BookMeta['status'] } ) => wrap(() => registry.updateMeta(bookId, patch)) ) }