import { AuditLogEvent } from 'discord.js';
import type { NucleusClient } from "../utils/client.js";
import type { GuildEmoji, GuildAuditLogsEntry } from 'discord.js'
export const event = "emojiUpdate";

export async function callback(client: NucleusClient, oldEmoji: GuildEmoji, newEmoji: GuildEmoji) {
    const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderEmoji } = client.logger;

    const auditLog = (await getAuditLog(newEmoji.guild, AuditLogEvent.EmojiCreate))
        .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === newEmoji.id)[0];
    if (!auditLog) return;
    if (auditLog.executor!.id === client.user!.id) return;

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