import { ServiceStatus , ServiceStatusLevels , ServiceStatusLevel } from './types' ; /**
 * Returns a single  ServiceStatus that summarizes the most severe status level from a group of statuses.
 *  param statuses export const getSummaryStatus = ( statuses , { allAvailableSummary = `All services are available` } = { } ) : ServiceStatus => { const { highestLevel , highestStatuses } = highestLevelSummary ( statuses ) ; if ( highestLevel === ServiceStatusLevels . available ) { return { level : ServiceStatusLevels . available , summary : allAvailableSummary , } ; } else if ( highestStatuses . length === 1 ) { const [ serviceName , status ] = highestStatuses [ 0 ] ! as [ string , ServiceStatus ] ; return { ... status , summary : `[${ serviceName }]: ${ status . summary ! }` , detail : status . detail ?? `See the status page for more information` , meta : { affectedServices : { [ serviceName ] : status } , } , } ; } else { return { level : highestLevel , summary : `[${ highestStatuses . length }] services are ${ highestLevel . toString ( ) }` , detail : `See the status page for more information` , meta : { affectedServices : Object . fromEntries ( highestStatuses ) , } , } ; } } ; type StatusPair = [ string , ServiceStatus ] ; const highestLevelSummary = ( statuses ) : { highestLevel : ServiceStatusLevel ; highestStatuses : StatusPair [ ] ; } => { let highestLevel = ServiceStatusLevels . available ; let highestStatuses = [ ] ; for ( const pair of statuses ) { if ( pair [ 1 ] . level === highestLevel ) { highestStatuses . push ( pair ) ; } else if ( pair [ 1 ] . level > highestLevel ) { highestLevel = pair [ 1 ] . level ; highestStatuses = [ pair ] ; } } return { highestLevel , highestStatuses , } ; } ;