import { ProductSearchResponseAttributes } from '@spiffy-ai/commerce-api-client';

export const isApiProductSearchResponseAttributes = (
  attributes: unknown,
): attributes is ProductSearchResponseAttributes => {
  if (attributes == null || typeof attributes !== 'object') {
    return false;
  }

  if ('generated_query' in attributes && typeof attributes.generated_query !== 'string') {
    return false;
  }

  if (
    'product_count' in attributes &&
    attributes.product_count != null &&
    typeof attributes.product_count !== 'number'
  ) {
    return false;
  }

  return true;
};
