const { HttpsProxyAgent } = require("https-proxy-agent");

function getAxiosProxyConfig(proxy) {
    if (!proxy) return {};

    try {
        // Ensure proxy URL includes protocol, username, password, host, and port
        const agent = new HttpsProxyAgent(proxy);
        console.log(`🔧 Using proxy: ${proxy}`);
        return {
            httpsAgent: agent,
            proxy: false // Disable Axios default proxy handling
        };
    } catch (error) {
        console.error(`❌ Failed to create proxy agent: ${error.message}`);
        return {};
    }
}

module.exports = { getAxiosProxyConfig };