/**
 * Cross-process command dedup via SQLite.
 * When multiple bot containers share the same DB, only the first INSERT wins.
 */

export function tryClaimBotMessage(db, messageId, command) {
  if (!db || !messageId || !command) return Promise.resolve(true);

  return new Promise((resolve, reject) => {
    db.run(
      `INSERT OR IGNORE INTO bot_message_dedup (messageId, command, processedAt)
       VALUES (?, ?, ?)`,
      [messageId, command, new Date().toISOString()],
      function onRun(err) {
        if (err) reject(err);
        else resolve(this.changes > 0);
      }
    );
  });
}
