import { Injectable } from '@angular/core';
import { Mapper } from './mapper';

@Injectable()
export class FeaturesToAssortmentMapping implements Mapper<{ key: string; name: string; value?: string }[], string> {
  get sourceName(): string {
    return 'Features';
  }

  get targetName(): string {
    return 'Assortment';
  }

  map(source: { key: string; name: string; value?: string }[]): string {
    if (!source || (!!source.length && !source.find((feat) => feat.hasOwnProperty('key')))) {
      return '';
    }

    return source.reduce((acc, curr) => acc + `${curr.name || ''}|${curr.key.slice(curr.key.length - 1, curr.key.length)}`, '');
  }
}

/**
 * 
 * source.features.map((feature) => ({
          name: feature.value,
          key: feature.key[feature.key.length - 1],
        })),
 * 
 * 
 */
