const db = require('../config/database');

const TokenBlacklist = {
    add: (token, expiresAt, callback) => {
        const query = 'INSERT INTO token_blacklist (token, expires_at) VALUES (?, ?)';
        db.query(query, [token, expiresAt || null], callback);
    },

    isBlacklisted: (token, callback) => {
        const query = 'SELECT id FROM token_blacklist WHERE token = ? LIMIT 1';
        db.query(query, [token], (err, results) => {
            if (err) {
                return callback(err);
            }
            callback(null, results.length > 0);
        });
    }
};

module.exports = TokenBlacklist;
