import type { IDataExport } from "../data-export.interface";
import type { DsrFormat, UserDataBundle } from "../dsr-types";
import type { HandlerResponse } from "./handler-types";

export type ExportHandlerInput = {
  subjectId: string;
  format: DsrFormat;
};

export function createExportHandler(dataExport: IDataExport) {
  return async (
    input: ExportHandlerInput,
  ): Promise<HandlerResponse<UserDataBundle>> => {
    const bundle = await dataExport.exportSubjectData(
      input.subjectId,
      input.format,
    );
    const headers: Record<string, string> =
      input.format === "json-ld"
        ? { "Content-Type": "application/ld+json" }
        : { "Content-Type": "application/json" };
    return { status: 200, body: bundle, headers };
  };
}
