export function isNotifiableCriticalAlert(alert) {
  return (
    alert.severity === 'CRITICAL'
    && (alert.status === 'OPEN' || alert.status === 'ESCALATED')
  )
}

export function detectNewCriticalAlerts(alerts, lastSeenIds, seeded = false) {
  const criticalOpen = alerts.filter(isNotifiableCriticalAlert)
  const criticalIds = criticalOpen.map(alert => alert.id)

  if (!seeded) {
    return { newAlerts: [], nextSeenIds: criticalIds, seeded: true }
  }

  const seen = new Set(lastSeenIds)
  const newAlerts = criticalOpen.filter(alert => !seen.has(alert.id))
  return { newAlerts, nextSeenIds: criticalIds, seeded: true }
}
