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

@Pipe({
  name: 'environmentChannel',
})
@Injectable()
export class EnvironmentChannelPipe implements PipeTransform {
  channels = new Map([
    [0, ''],
    [2, 'Filiale'],
    [4, 'HSC'],
    [8, 'Online'],
  ]);

  transform(clientChannel: EnvironmentChannel = 0, join: string = ' '): any {
    if (clientChannel === 0) {
      return this.channels.get(0);
    }

    const channelOnlineMobileApp: number = clientChannel;
    if (channelOnlineMobileApp === 8 || channelOnlineMobileApp === 16 || channelOnlineMobileApp === 24) {
      return 'hugendubel.de';
    }

    const channels: string[] = [];
    this.channels.forEach((value, key) => {
      // tslint:disable-next-line: no-bitwise
      if ((clientChannel | key) === key) {
        channels.push(value);
      }
    });
    return channels.join(join);
  }
}
