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

@Pipe({
  name: 'shippingAddress',
})
export class ShippingAddressPipe implements PipeTransform {
  transform(value: ShippingAddressDTO, ...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 '';
  }
}
