// Local type aliases mirroring exports from `@repo/core-dsr`.
// Kept inline to avoid a build-graph cycle between core-testing (tooling)
// and core-dsr (optional core). Same pattern used by RecordingAuditLog,
// RecordingConsent, and other recording doubles.

type DsrFormat = "json" | "json-ld";

type SubjectReference = {
  rowId: string;
  linkedField: string;
  linkedThrough: string;
};

type CollectionDataBucket = {
  asSelf?: Array<Record<string, unknown>>;
  asReference?: SubjectReference[];
};

type UserDataBundle = {
  subjectId: string;
  exportedAt: string;
  format: DsrFormat;
  data: Record<string, CollectionDataBucket>;
  auditLog?: unknown[];
  "@context"?: string | Record<string, unknown>;
};

/** Recorded call to exportSubjectData. */
export type RecordedExportCall = {
  subjectId: string;
  format: DsrFormat;
};

/**
 * Test-side recording double for IDataExport. Records all exportSubjectData
 * calls for assertion while returning an empty but structurally-correct bundle.
 *
 * Use directly via constructor injection:
 *   const exporter = new RecordingDataExport();
 *   const uc = myUseCase(exporter);
 *   await uc({ ... });
 *   expect(exporter.calls).toHaveLength(1);
 *   expect(exporter.calls[0]?.format).toBe("json");
 */
export class RecordingDataExport {
  public calls: RecordedExportCall[] = [];

  async exportSubjectData(
    subjectId: string,
    format: DsrFormat,
  ): Promise<UserDataBundle> {
    this.calls.push({ subjectId, format });
    return {
      subjectId,
      exportedAt: new Date().toISOString(),
      format,
      data: {},
    };
  }

  reset(): void {
    this.calls = [];
  }
}
