import client from "./client.js";
import type { GuildConfig } from "./database.js";

interface GuildData {
    lastUpdated: number;
    filters: GuildConfig["filters"];
    logging: GuildConfig["logging"];
    tickets: GuildConfig["tickets"];
    tags: GuildConfig["tags"];
    autoPublish: GuildConfig["autoPublish"];
}

class Memory {
    memory: Map<string, GuildData>;
    constructor() {
        this.memory = new Map<string, GuildData>();

        setInterval(() => {
            for (const [guild, guildData] of this.memory.entries()) {
                if (guildData.lastUpdated + 15 * 60 * 1000 < Date.now()) {
                    this.memory.delete(guild);
                }
            }
        }, 1000 * 60 * 30);
    };

    async readGuildInfo(guild: string): Promise<GuildData> {
        if (!this.memory.has(guild)) {
            const guildData = await client.database.guilds.read(guild);
            this.memory.set(guild, {
                lastUpdated: Date.now(),
                filters: guildData.filters,
                logging: guildData.logging,
                tickets: guildData.tickets,
                tags: guildData.tags,
                autoPublish: guildData.autoPublish
            });
        }
        return this.memory.get(guild)!;
    };

    async forceUpdate(guild: string) {
        if (this.memory.has(guild)) this.memory.delete(guild);
    }
}

export default Memory;
