import { ReturnProcess, ReturnProcessQuestion } from '../../models';
import { CategoryQuestions, ProductCategory } from '../../questions';
import { tolinoQuestions } from './get-tolino-questions.helper';

/**
 * Returns the list of return process questions based on the product category.
 *
 * If the product category is `Tolino`, additional dynamic logic is applied
 * via `tolinoQuestions(process)` to adjust the question flow based on prior answers.
 * For all other categories, the predefined question set from `CategoryQuestions` is returned.
 *
 * If the product category is missing or invalid, `undefined` is returned.
 *
 * @param process - The current return process state, including the product category and answers.
 * @returns The appropriate list of `ReturnProcessQuestion`s for the given process,
 *          or `undefined` if no valid category is present.
 */
export const getReturnProcessQuestions = (
  process: ReturnProcess,
): ReturnProcessQuestion[] | undefined => {
  const category = process.productCategory as ProductCategory;

  if (!category) return undefined;

  if (category === ProductCategory.Tolino) {
    return tolinoQuestions(process);
  }
  return CategoryQuestions[category as keyof typeof CategoryQuestions];
};
