import express from 'express';
import { LoginSystem } from '../../../../features/login';
import { adminNoteSystem } from '../../../../features/admin/notes';
import { ChatSystem } from '../../../../features/chat';
import { ChatColors } from '../../../../const/chat-colors';

export async function AccountAdminNoteRefresh(req: express.Request, res: express.Response): Promise<void> {
    if (!req.body.accountId) {
        res.status(400).send('Missing parameter');
    }

    if (!Number(req.body.accountId)) {
        res.status(500).send('Unable to parse given parameter');
    }

    const player = mp.players.toArray().find((player) => player.account?.id === Number(req.body.accountId));

    if (player && LoginSystem.IsLoggedIn(player)) {
        ChatSystem.AdminWarn(`${req.body.by} applied changes to ${player.name} (${player.id})'s admin-notes.`, 'account.admin.note');
        adminNoteSystem.loadAdminNotes(player as PlayerMpLoggedIn, true);
    }

    res.sendStatus(200);
}
