import { Pipe, PipeTransform } from '@angular/core';
import { BuyerDTO } from '@swagger/checkout';

@Pipe({
  name: 'buyerName',
})
export class BuyerNamePipe implements PipeTransform {
  transform(buyer: BuyerDTO, ...args: any[]): any {
    if (buyer) {
      const organisationParts = [buyer?.organisation?.name].filter((f) => !!f);

      const customerParts = [buyer?.lastName, buyer?.firstName].filter((f) => !!f);

      return [organisationParts.join(), customerParts.join(' ')].filter((f) => !!f).join(' - ');
    }

    return '';
  }
}
