import { Channel } from 'channel/channel' ; class export class ChannelServer { private static nextChannelId = 1 ; private static formatServerName ( serverName , serverIndex , totalServers ) { return `${ serverName } [${ serverIndex }/${ totalServers }]` ; } private static formatChannelName ( serverName , serverIndex , channelIndex ) { return `${ serverName } ${ serverIndex }-${ channelIndex }` ; } public name : string ; public index : number ; public channels : Channel [ ] ; constructor ( serverName , serverIndex , totalServers , numOfChannels ) { this . name = ChannelServer . formatServerName ( serverName , serverIndex , totalServers ) ; this . index = serverIndex ; this . channels = [ ] ; for ( let index = 0 ; index < numOfChannels ; index ++ ) { const newChannelIndex = ChannelServer . nextChannelId ; const newChannelName = ChannelServer . formatChannelName ( serverName , serverIndex , newChannelIndex ) ; this . channels . push ( new Channel ( newChannelIndex , newChannelName ) ) ; ChannelServer . nextChannelId ++ ; } } /**
     * getChannelByIndex
     */ public getChannelByIndex ( index ) { for ( const channel of this . channels ) { if ( channel . index === index ) { return channel ; } } return null ; } }