function mergeDeviceData(siwDevices, merakiClients) { return siwDevices.map(siw => { // Primary match: name let match = merakiClients.find(m => m.description && siw.name && m.description.toLowerCase().includes(siw.name.toLowerCase()) ); // Fallback: MAC address if (!match && siw.mac) { match = merakiClients.find(m => m.mac && m.mac.toLowerCase() === siw.mac.toLowerCase() ); } return { name: siw.name || siw.deviceName || 'Unknown', ip: siw.ip || siw.ipAddress || match?.ip || 'N/A', status: match?.status === 'Online' ? '✅ Connected' : '❌ Disconnected', lastSeen: match?.lastSeen ? new Date(match.lastSeen * 1000).toLocaleString() : 'N/A', deeplink: match?.mac ? `https://dashboard.meraki.com/o/${match.orgId || 'your-org'}/n/${match.networkId || 'your-net'}/clients?mac=${match.mac}` : null }; }).sort((a, b) => a.name.localeCompare(b.name)); } module.exports = { mergeDeviceData };