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

export async function callback(client: NucleusClient, emoji: GuildEmoji) {
    const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
    if (!await isLogging(emoji.guild.id, "emojiUpdate")) return;
    const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiCreate))
    .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id)[0];
    if (!auditLog) return;
    if (auditLog.executor!.id === client.user!.id) return;
    const data = {
        meta: {
            type: "emojiCreate",
            displayName: "Emoji Created",
            calculateType: "emojiUpdate",
            color: NucleusColors.green,
            emoji: "GUILD.EMOJI.CREATE",
            timestamp: emoji.createdTimestamp
        },
        list: {
            emojiId: entry(emoji.id, `\`${emoji.id}\``),
            emoji: entry(emoji.name, renderEmoji(emoji)),
            createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
            created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp))
        },
        hidden: {
            guild: emoji.guild.id
        }
    };
    log(data);
}

