import { dirname, join } from "path";
import { fileURLToPath } from "url";

import type{ IEnvironment } from "../src/interfaces/environment";

const __dirname : string = join(dirname(fileURLToPath(import.meta.url)), "..");

const environment : IEnvironment = {
    development: process.env.NODE_ENV === "development" || process.argv.includes("--dev"),

    fastify: {
        host: process.env.HOST || "0.0.0.0",
        port: parseInt(process.env.PORT || "8080"),
    },

    discord: {
        auth: {
            token: process.env.DISCORD_TOKEN || "",
            guildId: process.env.DISCORD_GUILD_ID || "",
        },
        watchIds: [
            (() => {
                const id = process.env.DISCORD_USER_ID;
                if (id && /^\d+$/.test(id)) {
                    return BigInt(id);
                }
                return BigInt(0);
            })()
        ],
    },

    paths: {
        src: __dirname,
        www: {
            root: join(__dirname, "src", "www"),
            views: join(__dirname, "src", "www", "views"),
            public: join(__dirname, "src", "www", "public")
        }
    }
};

export default environment;
export { environment };
