export const event = "stickerDelete";

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