import Taro from '@tarojs/taro';

import { CollectEventName, ReportEventId } from '@/constants/event';
import { logWithPrefix } from '@/utils/common';
import { getUserId } from '@/utils/user';

const log = logWithPrefix('event');
const logManager = Taro.getRealtimeLogManager();
const deviceInfo = Taro.getDeviceInfo();

export const collectEvent = (eventName: CollectEventName, params: BL.Anything = {}) => {
  if (!logManager) return;
  const collectInfo = {
    ...deviceInfo,
    ...params,
    eventName,
    userId: getUserId(),
  };
  logManager.info(collectInfo);
  log('devEvent', collectInfo);
};

export const reportEvent = (eventId: ReportEventId, params: BL.Anything = {}) => {
  Taro.reportEvent(eventId, params);
  log('reportEvent', eventId, params);
};
