export const event = "emojiUpdate";

export async function callback(client, oe, ne) {
    const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderEmoji } = client.logger;

    if (oe.name === ne.name) return;
    const auditLog = await getAuditLog(ne.guild, "EMOJI_UPDATE");
    const audit = auditLog.entries.first();
    if (audit.executor.id === client.user.id) return;

    const changes = {
        emojiId: entry(ne.id, `\`${ne.id}\``),
        emoji: entry(ne.id, renderEmoji(ne)),
        edited: entry(ne.createdTimestamp, renderDelta(ne.createdTimestamp)),
        editedBy: entry(audit.executor.id, renderUser((await ne.guild.members.fetch(audit.executor.id)).user)),
        name: entry([oe.name, ne.name], `\`:${oe.name}:\` -> \`:${ne.name}:\``)
    };
    const data = {
        meta: {
            type: "emojiUpdate",
            displayName: "Emoji Edited",
            calculateType: "emojiUpdate",
            color: NucleusColors.yellow,
            emoji: "GUILD.EMOJI.EDIT",
            timestamp: audit.createdTimestamp
        },
        list: changes,
        hidden: {
            guild: ne.guild.id
        }
    };
    log(data);
}
