import {
  Suggestion as CommerceSuggestion,
  SuggestionCategory,
} from '@spiffy-ai/commerce-api-client';

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

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

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

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

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

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

  return true;
};
