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

export const isApiPDPAttributes = (data: unknown): data is PDPAttributes => {
  if (data == null || typeof data !== 'object') {
    return false;
  }

  if (!('product_id' in data) || typeof data.product_id !== 'string') {
    return false;
  }

  if (
    'parent_product_id' in data &&
    data.parent_product_id !== null &&
    typeof data.parent_product_id !== 'string'
  ) {
    return false;
  }

  if ('url' in data && data.url != null && typeof data.url !== 'string') {
    return false;
  }

  return true;
};
