/** The predefined environment values */
import * as fs from "fs";

const envValue: string[] = [
    "MONGOOSE_STRING", "API_PORT", "SHORTENER_PORT", "CDN_PORT", "AS_PORT"
]

/** Checks if the provided value is registered in process.env */
const isRegistered = (value: string) => process.env[value];

/** Checks if the gbucket.json file exists */
const checkGoogleAuthentication = () => {
    if (!fs.existsSync(process.cwd() + "/gbucket.json")) {
        console.warn("[ContentDelivery] Could not find gbucket.json. Content delivery disabled.");
        process.env.DISABLE_CONTENT_DELIVERY = "true"
    }
}

/** Validates the .env file */
module.exports.validate = () => {
    for (let value of envValue) {
        if (!isRegistered(value)) throw new Error(`Please register the environment value '${value}' in your .env file`);
    }

    checkGoogleAuthentication();
}