import express from 'express';

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

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

    const account = mp.players.toArray().find((player) => player.account?.id === Number(req.params.accountId));
    res.send({
        ingame: account ? true : false,
        character: account
            ? {
                  characterId: account?.character?.id,
                  characterName: account?.character?.name,
              }
            : undefined,
    });
}
