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"];
}

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
            });
        }
        return this.memory.get(guild)!;
    };

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

export default Memory;
