// Guild member join/leave events (Phase 6b). Bot-owned; the site reads these for
// the moderation dashboard's members feed + invite-usage view. Schema in
// server/db/schema.sql (member_events).
const db = require('../db')

async function record({ guildId, eventType, discordUserId, username, inviteCode, inviterId, inviterTag }) {
  await db.query(
    `INSERT INTO member_events (guild_id, event_type, discord_user_id, username, invite_code, inviter_id, inviter_tag)
     VALUES (?, ?, ?, ?, ?, ?, ?)`,
    [guildId, eventType, discordUserId, username || null, inviteCode || null, inviterId || null, inviterTag || null],
  )
}

module.exports = { record }
