// Environment configuration
require('dotenv').config();

module.exports = {
    // Server configuration
    PORT: process.env.PORT || 3000,
    NODE_ENV: process.env.NODE_ENV || 'development',
    
    // QuickBooks configuration
    QB_CLIENT_ID: process.env.QB_OAUTH2_CLIENT_ID || process.env.QB_CLIENT_ID,
    QB_CLIENT_SECRET: process.env.QB_OAUTH2_CLIENT_SECRET || process.env.QB_CLIENT_SECRET,
    QB_REDIRECT_URI: process.env.QB_REDIRECT_URI || `${process.env.FRONTEND_URL || 'http://localhost:3000'}/auth/callback`,
    QB_ENVIRONMENT: process.env.QB_ENVIRONMENT || 'sandbox',
    QB_BASE_URL: process.env.QB_BASE_URL || 'http://localhost:3000',
    
    // Security
    ADMIN_API_KEY: process.env.ADMIN_API_KEY,
    ADMIN_USERNAME: process.env.ADMIN_USERNAME || 'admin',
    ADMIN_PASSWORD: process.env.ADMIN_PASSWORD || 'admin123',
    
    // Rate limiting
    RATE_LIMIT_WINDOW_MS: parseInt(process.env.RATE_LIMIT_WINDOW_MS) || 900000, // 15 minutes
    RATE_LIMIT_MAX_REQUESTS: parseInt(process.env.RATE_LIMIT_MAX_REQUESTS) || 100,
    
    // Validation
    validateRequired() {
        const required = [
            'ADMIN_API_KEY'
        ];
        
        const missing = required.filter(key => !process.env[key]);
        if (missing.length > 0) {
            throw new Error(`Missing required environment variables: ${missing.join(', ')}`);
        }
    }
};
