module.exports = Self => {
    Self.remoteMethodCtx('getCurrentWorkerMana', {
        description: 'Returns the mana of the logged worker',
        accessType: 'READ',
        accepts: [],
        returns: {
            type: 'number',
            root: true
        },
        http: {
            path: `/getCurrentWorkerMana`,
            verb: 'GET'
        }
    });

    Self.getCurrentWorkerMana = async ctx => {
        let userId = ctx.req.accessToken.userId;

        let workerMana = await Self.app.models.WorkerMana.findOne({
            where: {workerFk: userId},
            fields: 'amount'
        });

        return workerMana ? workerMana.amount : 0;
    };
};