"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CloudConfig = void 0;
class CloudConfig {
    constructor() {
        this.cloudName = "";
        this.apiKey = "";
        this.apiSecret = "";
        let envVar = undefined;
        if (typeof process !== "undefined") {
            if (process.env?.CLOUDINARY_URL) {
                envVar = process.env.CLOUDINARY_URL;
            }
        }
        else if (typeof Deno !== "undefined" && Deno.env?.get) {
            envVar = Deno.env.get("CLOUDINARY_URL");
        }
        if (envVar) {
            try {
                const url = new URL(envVar);
                this.cloudName = url.host;
                this.apiKey = url.username || "";
                this.apiSecret = url.password || "";
                // Automatically set CLOUDINARY_CLOUD_NAME if not already set
                // This ensures the SDK can find cloudName during initialization
                if (this.cloudName && typeof process !== "undefined" && !process.env.CLOUDINARY_CLOUD_NAME) {
                    process.env.CLOUDINARY_CLOUD_NAME = this.cloudName;
                }
            }
            catch (error) {
                throw new Error(`Invalid CLOUDINARY_URL: '${envVar}'`);
            }
        }
    }
}
exports.CloudConfig = CloudConfig;
//# sourceMappingURL=cloudConfig.js.map