import { UserEvent, UserEventCategory } from '@spiffy-ai/commerce-api-client';

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

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

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

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

  return true;
};
