import dotenv from "dotenv";

if (process.env.NODE_ENV === "development") {
    dotenv.config({
        path: "../.env",
    });
    dotenv.config({
        path: "../db.env",
    });

    process.env.TYPEORM_HOST = "localhost";
    process.env.NOCTBOT_ADDR = "localhost";
    process.env.WEB_DATA_PATH = "./web_data";
    process.env.PORT = "3000";
    process.env.TYPEORM_USERNAME = process.env.DB_USERNAME;
    process.env.TYPEORM_PASSWORD = process.env.DB_PASSWORD;
    process.env.TYPEORM_DATABASE = process.env.DB_NAME;
}

export const ENV = {
    BOT_CLIENT_ID: "",
    BOT_CLIENT_SECRET: "",
    WEB_AUTH_URI: "",
    WEB_DATA_PATH: "",
    HCAPTCHA_SITEKEY: "",
    HCAPTCHA_SECRET: "",
};

function isValid(): boolean {
    let valid = true;
    Object.keys(ENV).forEach((envKey) => {
        if (!process.env[envKey]) {
            valid = false;
            return;
        }
        const c = envKey as keyof typeof ENV;
        ENV[c] = process.env[envKey] as string;
    });
    return valid;
}

export const IS_VALID = isValid();
