// import { MessageInterface } from '../../lib/communication-interface/MessageInterface';
// import { BaseDataStore } from '../../lib/db/DataStore';
// import { ObjectStore } from '../../lib/db/DBAccess';
// import { DBFactory } from '../../lib/db/DBFactory';
// import { ContactRole } from '../../lib/libDto/ContactDto';
// import { LongAsyncRemoteFunction } from '../../lib/objectTransport/LongAsyncRemoteFunction';
// import getFactory from '../db';
// import { NoteDto } from '../Dto/NoteDto';

// interface NoteParameterMap {
//     'shareNote': { noteId: string, userId: string };
//     'recieveNote': { noteId: string, title: string, content: string };
//     'addNote': { title: string, content: string };
//     'updateNote': { noteId: string, title: string, content: string };
//     'getNotes': Record<string, never>;
// }

// export class NoteStore extends BaseDataStore {
//     private noteDao?: ObjectStore<NoteDto>;
//     private larf?: LongAsyncRemoteFunction<NoteParameterMap>;

//     protected async init() {
//         this.larf = this.getLarf<NoteParameterMap>('noteStore');
//         this.larf.register('shareNote', this.shareNote.bind(this));
//         this.larf.register('recieveNote', this.recieveNote.bind(this));
//         this.noteDao = await this.getDao(NoteDto);
//     }

//     async getNotes(from: string): Promise<NoteDto[]> {
//         await this._initPromise;

//         if (ContactRole.SameUser === await this.contactManager.getContactRoleFromAddress(from)) {
//             return this.noteDao!.getAll();
//         } else {
//             throw new Error('User is not allowed to get notes');
//         }
//     }

//     async addNote(from: string, { title, content }: NoteParameterMap['addNote']): Promise<NoteDto> {
//         await this._initPromise;
//         if (ContactRole.SameUser === await this.contactManager.getContactRoleFromAddress(from)) {
//             const note = new NoteDto(title, content);
//             return await this.noteDao!.add(note);
//         } else {
//             throw new Error('User is not allowed to add notes');
//         }
//     }

//     async updateNote(from: string, { noteId, title, content }: NoteParameterMap['updateNote']): Promise<void> {
//         await this._initPromise;
//         if (ContactRole.SameUser === await this.contactManager.getContactRoleFromAddress(from)) {
//             const note = await this.noteDao!.get(noteId);
//             if (!note) {
//                 throw new Error('Note not found');
//             }
//             note.title = title;
//             note.content = content;
//             await this.noteDao!.update(note);
//         } else {
//             throw new Error('User is not allowed to update notes');
//         }
//     }

//     async shareNote(from: string, { noteId, userId }: NoteParameterMap['shareNote']): Promise<void> {
//         await this._initPromise;
//         if (ContactRole.SameUser === await this.contactManager.getContactRoleFromAddress(from)) {
//             const note = await this.noteDao!.get(noteId);
//             if (!note) {
//                 throw new Error('Note not found');
//             }
//             const { title, content } = note;
//             await this.larf!.call('recieveNote', userId, { noteId, title, content });
//         } else {
//             throw new Error('User is not allowed to share notes');
//         }
//     }

//     async recieveNote(from: string, { noteId, title, content }: NoteParameterMap['recieveNote']): Promise<void> {
//         await this._initPromise;
//         const contactRole = await this.contactManager.getContactRoleFromAddress(from);
//         if (ContactRole.Contact === contactRole) {
//             const existingNote = await this.noteDao!.get(noteId);
//             if (existingNote) {
//                 existingNote.title = title;
//                 existingNote.content = content;
//                 await this.noteDao!.update(existingNote);
//                 return;
//             }
//             const note = new NoteDto(title, content, noteId);
//             await this.noteDao!.add(note);
//         } else {
//             throw new Error('Can not recieve note from unknown user');
//         }
//     }
// }