/**
 * Integration Example: How to use Devicely Advanced Logger in your existing code
 * This shows migration from console.log to the new logging system
 */

// ============================================================================
// BEFORE: Basic console logging
// ============================================================================

console.log('Starting device connection...');
console.log('Device connected:', deviceId);
console.error('Error occurred:', error);

// ============================================================================
// AFTER: Advanced Devicely Logging
// ============================================================================

const { DevicelyLogger } = require('./advanced-logger');
const logger = new DevicelyLogger('DeviceManager');

// Public user sees: "✅ Device connected" 
// Developer sees: "✅ Device connected to 00008030...802E" with device info
// Creator sees: Full device info + internal diagnostics
logger.success('Device connected');

// Specific device logging with context
const device = logger.device('00008030-001824A82E90802E');
device.connect({
  platform: 'iOS',
  name: 'iPhone 12 Pro',
  version: '17.4.1'
});

// Command logging with performance tracking
logger.startTimer('screenshot');
logger.command('00008030-001824A82E90802E', 'screenshot', {
  format: 'png',
  quality: 0.8
}, 150);
logger.endTimer('screenshot');

// Network request logging with automatic redaction
logger.network('POST', '/wda/screenshot', 200, {
  sessionId: 'secret_session_123',
  authToken: 'Bearer xyz...'
}, 150);

// Error handling with context preservation
try {
  // Some device operation
} catch (error) {
  logger.error('Screenshot capture failed', error, {
    deviceId: '00008030-001824A82E90802E',
    attemptCount: 3,
    lastKnownState: 'connected'
  });
}

// ============================================================================
// INTEGRATION WITH EXISTING SERVER.JS
// ============================================================================

// Replace existing logger import
// OLD: const Logger = require('./logger');
// NEW: const { DevicelyLogger } = require('./advanced-logger');

// Your existing code will work with zero changes!
const logger = new DevicelyLogger('Server');

// All your existing methods work:
logger.startup('Server started on port 3000');  // Now shows as ✅ success
logger.debug('WebSocket connected');            // Respects debug levels
logger.result('Command executed successfully'); // Now shows as 📱 info

// ============================================================================
// PERFORMANCE & SECURITY EXAMPLES
// ============================================================================

// Automatic memory tracking (Creator mode only)
logger.memory();

// Security event logging (Creator mode only) 
logger.security('Failed authentication attempt', {
  ipAddress: '192.168.1.100',
  userAgent: 'AttackBot/1.0',
  attemptCount: 5
});

// Performance metrics
logger.performance('command_latency', 75, 'ms');
logger.performance('device_count', 3, 'devices');

// Session statistics
const stats = logger.getSessionStats();
console.log('Session Info:', {
  id: stats.sessionId,
  uptime: `${Math.round(stats.uptime / 1000)}s`,
  commands: stats.totalCommands,
  avgTime: `${Math.round(stats.avgCommandTime)}ms`
});

module.exports = logger;