import type { NucleusClient } from "../utils/client.js";
import { AuditLogEvent, GuildAuditLogsEntry, Sticker } from "discord.js";

export const event = "stickerDelete";

export async function callback(client: NucleusClient, sticker: Sticker) {
    const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
    if (!(await isLogging(sticker.guild!.id, "stickerUpdate"))) return;
    const auditLog = (await getAuditLog(sticker.guild!, AuditLogEvent.StickerDelete)).filter(
        (entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === sticker.id
    )[0]!;
    if (auditLog.executor!.id === client.user!.id) return;
    const data = {
        meta: {
            type: "stickerDelete",
            displayName: "Sticker Deleted",
            calculateType: "stickerUpdate",
            color: NucleusColors.red,
            emoji: "GUILD.EMOJI.DELETE",
            timestamp: auditLog.createdTimestamp
        },
        list: {
            stickerId: entry(sticker.id, `\`${sticker.id}\``),
            sticker: entry(sticker.name, `\`${sticker.name}\``),
            deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
            created: entry(sticker.createdTimestamp, renderDelta(sticker.createdTimestamp)),
            deleted: entry(auditLog.createdTimestamp, renderDelta(auditLog.createdTimestamp))
        },
        hidden: {
            guild: sticker.guild!.id
        }
    };
    await log(data);
}
