import humanizeDuration from "humanize-duration";
export const event = "inviteCreate";

export async function callback(client, invite) {
    const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = invite.client.logger;
    const auditLog = await getAuditLog(invite.guild, "INVITE_CREATE");
    const audit = auditLog.entries.filter((entry) => entry.target.id === invite.id).first();
    if (audit.executor.id === client.user.id) return;
    const data = {
        meta: {
            type: "inviteCreate",
            displayName: "Invite Created",
            calculateType: "guildUpdate",
            color: NucleusColors.green,
            emoji: "INVITE.CREATE",
            timestamp: invite.createdTimestamp
        },
        list: {
            channel: entry(invite.channel.id, renderChannel(invite.channel)),
            link: entry(invite.url, invite.url),
            expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
            createdBy: entry(audit.executor.id, renderUser(audit.executor)),
            created: entry(invite.createdTimestamp, renderDelta(invite.createdTimestamp))
        },
        hidden: {
            guild: invite.guild.id
        }
    };
    log(data);
}
