module.exports = {
    friendlyName: 'Unregister FCM token',

    inputs: {
        userId: { type: 'string', required: true },
        deviceId: { type: 'string', required: true }
    },

    exits: {
        success: { responseType: 'ok' },
        forbidden: { responseType: 'forbidden' }
    },

    fn: async function (inputs, exits) {
        const { user } = this.req.token;
        if (!user || user.codeUser !== inputs.userId) {
            return exits.forbidden({ message: 'Token non autorisé pour cet utilisateur' });
        }

        await PushToken.destroy({ codeUser: inputs.userId, deviceId: inputs.deviceId });
        return exits.success({ ok: true });
    }
};


