"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateStartup = validateStartup;
exports.setupGracefulShutdown = setupGracefulShutdown;
const ai_config_1 = require("../config/ai.config");
/**
 * Validates all required configurations on application startup
 * Exits the process if critical configurations are missing
 */
async function validateStartup() {
    console.log('🚀 Starting application configuration validation...');
    try {
        // Validate AI configuration
        console.log('🔐 Validating AI API keys...');
        (0, ai_config_1.validateAPIKeys)();
        console.log('✅ AI API keys validated successfully');
        // Check if AI is properly configured
        if (!(0, ai_config_1.isAIConfigured)()) {
            throw new Error('AI services are not properly configured');
        }
        // Log configuration summary (without sensitive data)
        const configSummary = (0, ai_config_1.getConfigSummary)();
        console.log('📊 AI Configuration Summary:');
        console.log(JSON.stringify(configSummary, null, 2));
        // Validate database connection (if needed)
        await validateDatabaseConnection();
        // Validate Redis connection (if needed)
        await validateRedisConnection();
        console.log('✅ All startup validations passed successfully');
    }
    catch (error) {
        console.error('❌ Startup validation failed:', error);
        console.error('Please check your environment configuration and try again.');
        process.exit(1);
    }
}
/**
 * Validates database connection
 */
async function validateDatabaseConnection() {
    // This will be implemented when we set up TypeORM connection
    // For now, just log that we're skipping it
    console.log('⏭️  Database validation skipped (not yet configured)');
}
/**
 * Validates Redis connection
 */
async function validateRedisConnection() {
    // This will be implemented when we set up Redis
    // For now, just log that we're skipping it
    console.log('⏭️  Redis validation skipped (not yet configured)');
}
/**
 * Graceful shutdown handler
 */
function setupGracefulShutdown() {
    process.on('SIGINT', async () => {
        console.log('\n📴 Received SIGINT, shutting down gracefully...');
        await shutdown();
    });
    process.on('SIGTERM', async () => {
        console.log('\n📴 Received SIGTERM, shutting down gracefully...');
        await shutdown();
    });
}
/**
 * Performs graceful shutdown
 */
async function shutdown() {
    try {
        // Close database connections
        // Close Redis connections
        // Complete any pending operations
        console.log('✅ Graceful shutdown completed');
        process.exit(0);
    }
    catch (error) {
        console.error('❌ Error during shutdown:', error);
        process.exit(1);
    }
}
//# sourceMappingURL=startup-validation.js.map