export const getPartsOrderJobLineId = ({ line, originalLine, isReturn }) => {
  return line?.job_line_id || (isReturn ? originalLine?.joblineid : originalLine?.id);
};

export const buildSubmittedPartsOrderLines = ({ submittedLines = [], linesToOrder = [], isReturn }) => {
  return submittedLines.map((line, index) => {
    const jobLineId = getPartsOrderJobLineId({
      line,
      originalLine: linesToOrder?.[index],
      isReturn
    });

    return {
      ...line,
      job_line_id: jobLineId,
      ...(isReturn && { cm_received: false })
    };
  });
};

export const getSubmittedPartsOrderJobLineIds = (partsOrderLines = []) => {
  return partsOrderLines.map((line) => line.job_line_id).filter(Boolean);
};
