/**
 * GlitchTip Error Tracking Adapter
 * GlitchTip is Sentry-compatible.
 * This version uses the official @sentry/nextjs SDK.
 */

import * as Sentry from "@sentry/nextjs";
import type {
  ErrorTrackingAdapter,
  ErrorContext,
  ErrorTrackingConfig,
} from "./interfaces";

export class GlitchTipAdapter implements ErrorTrackingAdapter {
  constructor(_config: ErrorTrackingConfig) {
    // Sentry is initialized via sentry.*.config.ts files
  }

  captureException(error: any, context?: ErrorContext): void {
    Sentry.captureException(error, {
      extra: context?.extra,
      tags: context?.tags,
      user: context?.user as any,
      level: context?.level as any,
    });
  }

  captureMessage(message: string, context?: ErrorContext): void {
    Sentry.captureMessage(message, {
      extra: context?.extra,
      tags: context?.tags,
      user: context?.user as any,
      level: context?.level as any,
    });
  }

  setUser(user: ErrorContext["user"]): void {
    Sentry.setUser(user as any);
  }

  setTag(key: string, value: string): void {
    Sentry.setTag(key, value);
  }

  setExtra(key: string, value: any): void {
    Sentry.setExtra(key, value);
  }
}
