module.exports = Self => {
    Self.remoteMethodCtx('updateUser', {
        description: 'Update user data',
        accepts: [
            {
                arg: 'id',
                type: 'integer',
                description: 'The user id',
                required: true,
                http: {source: 'path'}
            }, {
                arg: 'name',
                type: 'string',
                description: 'The user name',
            }, {
                arg: 'nickname',
                type: 'string',
                description: 'The user nickname',
            }, {
                arg: 'email',
                type: 'string',
                description: 'The user email'
            }, {
                arg: 'lang',
                type: 'string',
                description: 'The user lang'
            }
        ],
        http: {
            path: `/:id/update-user`,
            verb: 'PATCH'
        }
    });

    Self.updateUser = async(ctx, id, name, nickname, email, lang) => {
        await Self.userSecurity(ctx, id);
        await Self.upsertWithWhere({id}, {name, nickname, email, lang});
    };
};