import { OrderTypeFeature } from '../models';
import { getOrderTypeFeature } from './get-order-type-feature.helper';

/**
 * Checks if the order type feature in the provided features record matches any of the specified order types.
 *
 * @param features - Record containing feature flags with an 'orderType' key
 * @param orderTypes - Array of order types to check against
 * @returns true if the feature's order type is one of the provided types, false otherwise
 *
 * @example
 * ```typescript
 * // Check if order type is a delivery type
 * const isDelivery = hasOrderTypeFeature(features, [
 *   OrderType.Delivery,
 *   OrderType.DigitalShipping,
 *   OrderType.B2BShipping
 * ]);
 *
 * // Check if order type requires a target branch
 * const hasTargetBranch = hasOrderTypeFeature(features, [
 *   OrderType.InStore,
 *   OrderType.Pickup
 * ]);
 * ```
 */
export function hasOrderTypeFeature(
  features: Record<string, string> | undefined,
  orderTypes: readonly OrderTypeFeature[],
): boolean {
  const orderType = getOrderTypeFeature(features);

  if (!orderType) {
    return false;
  }

  return orderTypes.includes(orderType);
}
