import { type MeInstance } from 'src/types/instance';
import { type MeUser } from 'src/types/user';
import { type AnalyticsThemeMode } from 'src/utils/themeMode';

import {
  clearUser as clearUserAmplitude,
  logEvent as logEventAmplitude,
  setPreferredMode as setPreferredModeAmplitude,
  setUser as setUserAmplitude,
} from './amplitude';
import {
  clearUser as clearUserClarity,
  setUser as setUserClarity,
} from './clarity';
import {
  clearUser as clearUserSentry,
  setUser as setUserSentry,
} from './sentry';

export const setUser = async (user: MeUser, instance: MeInstance) => {
  setUserSentry(user, instance);
  await setUserAmplitude(user, instance);
  setUserClarity(user, instance);
};

export const clearUser = () => {
  clearUserSentry();
  clearUserAmplitude();
  clearUserClarity();
};

export const logEvent = (
  eventName: string,
  eventProperties?: Record<string, unknown>,
) => {
  logEventAmplitude(eventName, eventProperties || {});
};

export const setPreferredMode = (mode: AnalyticsThemeMode) => {
  setPreferredModeAmplitude(mode);
};
