import { ReceiptItem } from '../../models';
import { ProductCategory } from '../../questions';

/**
 * Retrieves the product category for a given receipt item.
 *
 * @param item - The receipt item to extract the product category from.
 * @returns The product category if present in the item's features; otherwise, ProductCategory.Unknown.
 *
 * @remarks
 * - Returns ProductCategory.Unknown if the 'features' property is missing or does not contain a 'category'.
 * - Casts the 'category' feature to ProductCategory if present.
 */
export function getReceiptItemProductCategory(
  item: ReceiptItem,
): ProductCategory {
  if (!item.features) {
    return ProductCategory.Unknown;
  }
  return (
    (item.features['category'] as ProductCategory) || ProductCategory.Unknown
  );
}
