import {
  PLPAttributeCategory,
  PLPAttributes,
  PLPIdAttributes,
} from '@spiffy-ai/commerce-api-client';

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

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

  return true;
};

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

  if (
    !('category' in data) ||
    typeof data.category !== 'string' ||
    !Object.values(PLPAttributeCategory).includes(data.category as PLPAttributeCategory)
  ) {
    return false;
  }

  if (
    !('attributes' in data) ||
    typeof data.attributes !== 'object' ||
    !isApiPLPIdAttribute(data.attributes)
  ) {
    return false;
  }

  return true;
};
