import type { GuildAuditLogsEntry, GuildBan } from "discord.js";
import { purgeByUser } from "../actions/tickets/delete.js";
import type { HaikuClient } from "../utils/haiku/index.js";

export const event = "guildBanRemove";

export async function callback(client: HaikuClient, ban: GuildBan) {
    purgeByUser(ban.user.id, ban.guild);
    const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
    const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_REMOVE");
    const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === ban.user.id).first();
    if (audit.executor.id === client.user.id) return;
    await client.database.history.create("unban", ban.guild.id, ban.user, audit.executor, audit.reason);
    const data = {
        meta: {
            type: "memberUnban",
            displayName: "Member Unbanned",
            calculateType: "guildMemberPunish",
            color: NucleusColors.green,
            emoji: "PUNISH.BAN.GREEN",
            timestamp: new Date().getTime()
        },
        list: {
            memberId: entry(ban.user.id, `\`${ban.user.id}\``),
            name: entry(ban.user.id, renderUser(ban.user)),
            unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
            unbannedBy: entry(audit.executor.id, renderUser(audit.executor)),
            accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt))
        },
        hidden: {
            guild: ban.guild.id
        }
    };
    log(data);
}
