// Local type aliases mirroring IAnalytics from `@repo/core-analytics`.
// Kept inline to avoid a build-graph cycle between core-testing (tooling)
// and core-analytics (core). Same pattern used by recording-audit-log and
// recording-event-bus.

type AnalyticsAttributeValue = string | number | boolean;

type AnalyticsUser = {
  id: string;
};

export type RecordedTrack = {
  event: string;
  attributes?: Record<string, AnalyticsAttributeValue>;
};

export type RecordedIdentify = {
  user: AnalyticsUser;
  attributes?: Record<string, AnalyticsAttributeValue>;
};

export type RecordedPageView = {
  path: string;
  attributes?: Record<string, AnalyticsAttributeValue>;
};

export class RecordingAnalytics {
  public tracked: RecordedTrack[] = [];
  public identified: RecordedIdentify[] = [];
  public pageViewed: RecordedPageView[] = [];

  track(
    event: string,
    attributes?: Record<string, AnalyticsAttributeValue>,
  ): void {
    this.tracked.push({ event, attributes });
  }

  identify(
    user: AnalyticsUser,
    attributes?: Record<string, AnalyticsAttributeValue>,
  ): void {
    this.identified.push({ user, attributes });
  }

  pageView(
    path: string,
    attributes?: Record<string, AnalyticsAttributeValue>,
  ): void {
    this.pageViewed.push({ path, attributes });
  }

  flush(): Promise<void> {
    this.tracked = [];
    this.identified = [];
    this.pageViewed = [];
    return Promise.resolve();
  }

  reset(): void {
    this.tracked = [];
    this.identified = [];
    this.pageViewed = [];
  }
}
