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

@Pipe({
  name: 'payerAddress',
})
export class PayerAddressPipe implements PipeTransform {
  transform(value: PayerDTO, ...args: any[]): any {
    if (value) {
      const { organisation, firstName, lastName, address } = value;

      const parts = [
        organisation?.name,
        organisation?.department,
        [lastName, firstName].filter((f) => !!f).join(', '),
        [address?.street, address?.streetNumber].filter((f) => !!f).join(' '),
        [address?.zipCode, address?.city].filter((f) => !!f).join(' '),
      ]
        .filter((value) => value != null && value != '')
        .filter((value) => value.trim());
      return parts.join(' | ');
    }

    return '';
  }
}
