import { Return } from '../models';

/**
 * Helper function to extract and format receipt numbers from a return object.
 * Returns "Keine Belege vorhanden" if no receipts, otherwise returns formatted receipt numbers.
 *
 * @param {Return} returnData - The return object containing receipts
 * @returns {string} The formatted receipt numbers or message
 */
export const getReceiptNumberFromReturn = (returnData: Return): string => {
  if (!returnData?.receipts || returnData.receipts.length === 0) {
    return 'Keine Belege vorhanden';
  }

  const receiptNumbers = returnData.receipts
    .map((receipt) => receipt.data?.receiptNumber)
    .filter((receiptNumber) => receiptNumber && receiptNumber.length >= 12)
    .map((receiptNumber) => receiptNumber!.substring(6, 12));

  return receiptNumbers.length > 0 ? receiptNumbers.join(', ') : '';
};
