import { ipcMain } from 'electron'; import { createHandler } from '../database/LocalSystem.js'; import Character from '../database/models/Character.js'; import type { CharacterProps, CharacterPropsPost, CharacterAttribute } from '../database/models/Character.js'; interface AddCharacterData { character: CharacterPropsPost; bookId: string; } interface AddAttributeData { characterId: string; type: string; name: string; } // GET /character/list - Get character list interface GetCharacterListData { bookid: string; } ipcMain.handle('db:character:list', createHandler( function(userId: string, data: GetCharacterListData, lang: 'fr' | 'en'): CharacterProps[] { return Character.getCharacterList(userId, data.bookid, lang); } ) ); // GET /character/attribute - Get character attributes interface GetCharacterAttributesData { characterId: string; } ipcMain.handle('db:character:attributes', createHandler( function(userId: string, data: GetCharacterAttributesData, lang: 'fr' | 'en'): CharacterAttribute[] { return Character.getAttributes(data.characterId, userId, lang); } ) ); // POST /character/add - Add new character ipcMain.handle('db:character:create', createHandler( function(userId: string, data: AddCharacterData, lang: 'fr' | 'en'): string { return Character.addNewCharacter(userId, data.character, data.bookId, lang); } ) ); // POST /character/attribute/add - Add attribute to character ipcMain.handle('db:character:attribute:add', createHandler( function(userId: string, data: AddAttributeData, lang: 'fr' | 'en'): string { return Character.addNewAttribute(data.characterId, userId, data.type, data.name, lang); } ) ); // DELETE /character/attribute/delete - Delete character attribute interface DeleteAttributeData { attributeId: string; } ipcMain.handle('db:character:attribute:delete', createHandler( function(userId: string, data: DeleteAttributeData, lang: 'fr' | 'en'): boolean { return Character.deleteAttribute(userId, data.attributeId, lang); } ) ); // POST /character/update - Update character interface UpdateCharacterData { character: CharacterPropsPost; } ipcMain.handle('db:character:update', createHandler( function(userId: string, data: UpdateCharacterData, lang: 'fr' | 'en'): boolean { return Character.updateCharacter(userId, data.character, lang); } ) );