import express from 'express';
import { PlayerSystem } from '../../../../features/player';
import { staffSystem } from '../../../../features/staff';

export async function GetAllPlayers(req: express.Request, res: express.Response): Promise<void> {
    const allPlayers = mp.players.toArrayFast();
    const loggedInPlayers = allPlayers
        .filter((player) => player.character)
        .map((player) => {
            return {
                account: {
                    id: player.account?.id,
                    name: player.account?.name,
                    premium: PlayerSystem.IsPremium(player),
                    staff: staffSystem.isStaff(player),
                },
                character: {
                    id: player.character?.id,
                    name: player.character?.name,
                },
            };
        });

    res.send({
        count: allPlayers.length,
        loggedIn: loggedInPlayers,
    });
}
