const {
    UserModel,
    topSym
} = global.config
const {
    spaces
} = global.utils
const sequelize = global.database
const { Op } = require('sequelize');

module.exports = async (ctx) => {
    let topPlayer = await UserModel.findAll({
        attributes: ['name', [sequelize.fn('sum', sequelize.col('money')), 'money'], 'status'],
        group: ['name', 'status'],
        where: {
            telegram_id: {
                [Op.notIn]: [275416286, 6489664401]
            }
        },
        order: [
            [sequelize.literal('money'), 'DESC']
        ],
        limit: 15
    })
    let text = `🏆 Топ 15 игроков по балансу.\n\n`
    for(i=0; i<topPlayer.length; i++){
        text += `${topSym[i]}. ${topPlayer[i].status == 'bronze' ? `[🔺]` : ""}${topPlayer[i].status == 'silver' ? `[🔹]` : ""}${topPlayer[i].status == 'gold' ? `[🔸]` : ""} ${topPlayer[i].name} [₽${spaces(topPlayer[i].money)}]\n`
    }
    return await ctx.reply(text)
}