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

@Pipe({
  name: 'notificationsChannel',
  standalone: false,
})
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): string {
    const result: string[] = [];

    for (const [channel, name] of NotificationsChannelPipe.channels) {
      if (value & channel) {
        result.push(name);
      }
    }

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