import { Pipe, PipeTransform } from '@angular/core';
import { NotificationChannel } from '@swagger/oms';

@Pipe({
  name: 'notificationsChannel',
})
export class NotificationsChannelPipe implements PipeTransform {
  static channels = new Map<NotificationChannel, string>([
    [1, 'E-Mail'],
    [2, 'SMS'],
    [4, 'Telefon'],
    [8, 'Fax'],
    [16, 'Brief'],
  ]);

  transform(value: NotificationChannel = 0): any {
    const result: string[] = [];

    const channelKeys = Array.from(NotificationsChannelPipe.channels.keys());

    channelKeys.forEach((key) => {
      if (value & key) {
        result.push(NotificationsChannelPipe.channels.get(key));
      }
    });

    return result.join(' | ');
  }
}
