import client from "./client.js";
import EmojiEmbed from "./generateEmojiEmbed.js";
import { Record as ImmutableRecord } from "immutable";

const severitiesType = ImmutableRecord({
    "Critical": "Danger",
    "Warning": "Warning",
    "Info": "Success"
} as Record<string, "Danger" | "Warning" | "Success">);
const severities = severitiesType();

export default async function(type: string, guild: string, message: string | true, severity: "Critical" | "Warning" | "Info" = "Info") {
    const data = await client.database.guilds.read(guild);
    if (message === true) {
        return await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: false});
    }
    if (data.singleEventNotifications[type]) return;
    await client.database.guilds.write(guild, {[`singleEventNotifications.${type}`]: true});
    try {
        const channel = await client.channels.fetch(data.logging.staff.channel);
        if (!channel) return;
        await channel.send({embeds: [new EmojiEmbed()
            .setTitle(`${severity} notification`)
            .setDescription(message)
            .setStatus(severities.get(severity))
            .setEmoji("CONTROL.BLOCKCROSS")
        ]});
    } catch (err) {
        console.error(err);
    }
}
