import {
    BaseGuildTextChannel,
    GuildAuditLogsEntry,
    GuildBasedChannel,
    StageChannel,
    ThreadChannel,
    VoiceChannel
} from "discord.js";
// @ts-expect-error
import type { HaikuClient } from "jshaiku";
import getEmojiByName from "../utils/getEmojiByName.js";

export const event = "channelDelete";

export async function callback(client: HaikuClient, channel: GuildBasedChannel) {
    const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;

    const auditLog = await getAuditLog(channel.guild, "CHANNEL_DELETE");
    const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === channel.id).first();
    if (audit.executor.id === client.user.id) return;

    let emoji;
    let readableType;
    let displayName;
    switch (channel.type) {
        case "GUILD_TEXT": {
            emoji = "CHANNEL.TEXT.DELETE";
            readableType = "Text";
            displayName = "Text Channel";
            break;
        }
        case "GUILD_VOICE": {
            emoji = "CHANNEL.VOICE.DELETE";
            readableType = "Voice";
            displayName = "Voice Channel";
            break;
        }
        case "GUILD_CATEGORY": {
            emoji = "CHANNEL.CATEGORY.DELETE";
            readableType = "Category";
            displayName = "Category";
            break;
        }
        default: {
            emoji = "CHANNEL.TEXT.DELETE";
            readableType = "Channel";
            displayName = "Channel";
        }
    }
    const list: {
        channelId: { value: string; displayValue: string };
        name: { value: string; displayValue: string };
        topic?: { value: string; displayValue: string } | null;
        type: { value: string; displayValue: string };
        category: { value: string; displayValue: string };
        nsfw?: { value: string; displayValue: string } | null;
        created: { value: string; displayValue: string };
        deleted: { value: string; displayValue: string };
        deletedBy: { value: string; displayValue: string };
    } = {
        channelId: entry(channel.id, `\`${channel.id}\``),
        name: entry(channel.id, `${channel.name}`),
        topic: null,
        type: entry(channel.type, readableType),
        category: entry(
            channel.parent ? channel.parent.id : null,
            channel.parent ? channel.parent.name : "Uncategorised"
        ),
        nsfw: null,
        created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp)),
        deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
        deletedBy: entry(audit.executor.id, renderUser(audit.executor))
    };
    if ((channel instanceof BaseGuildTextChannel || channel instanceof StageChannel) && channel.topic !== null)
        list.topic = entry(channel.topic, `\`\`\`\n${channel.topic.replace("`", "'")}\n\`\`\``);
    else delete list.topic;
    if (
        channel instanceof BaseGuildTextChannel ||
        channel instanceof VoiceChannel ||
        channel instanceof ThreadChannel
    ) {
        const nsfw = channel instanceof ThreadChannel ? (channel as ThreadChannel).parent?.nsfw ?? false : channel.nsfw;
        list.nsfw = entry(
            nsfw,
            nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`
        );
    } else {
        delete list.nsfw;
    }

    const data = {
        meta: {
            type: "channelDelete",
            displayName: displayName + " Deleted",
            calculateType: "channelUpdate",
            color: NucleusColors.red,
            emoji: emoji,
            timestamp: audit.createdTimestamp
        },
        list: list,
        hidden: {
            guild: channel.guild.id
        }
    };
    log(data);
}
