import MemberNote from '../models/MemberNote.js';
import { checkAccess } from '../utils/userUtils.js';

import { devLog } from '../utils/logger.js';
class MemberNoteService {
    async addNoteToMember(userToken, clubId, memberId, content) {
        await checkAccess(userToken, clubId);
        return await MemberNote.create({ memberId, content });
    }

    async getNotesForMember(userToken, clubId, memberId) {
        devLog(userToken, clubId);
        await checkAccess(userToken, clubId);
        return await MemberNote.findAll({ 
            where: { memberId },
            order: [['createdAt', 'DESC']]
        });
    }

    async deleteNoteForMember(userToken, clubId, noteId) {
        await checkAccess(userToken, clubId);
        const note = await MemberNote.findByPk(noteId);
        if (!note) {
            throw new Error('Note not found');
        }
        await note.destroy();
    }
}

export default new MemberNoteService();
