import { httpClient } from "../../shared/api/httpClient";
import type { BlobResult } from "../../shared/api/types";

interface FileClient {
  getBlob(path: string, options?: { signal?: AbortSignal }): Promise<BlobResult>;
}

export function createFileApi(client: FileClient = httpClient) {
  return {
    preview(id: string, signal?: AbortSignal): Promise<BlobResult> {
      return client.getBlob(`documents/${id}/preview`, { signal });
    },

    download(id: string, signal?: AbortSignal): Promise<BlobResult> {
      return client.getBlob(`documents/${id}/download`, { signal });
    },
  };
}

export const fileApi = createFileApi();
