import { apiV2Fetch } from "#lib/api";
import { IArchiveFile } from "#entities/files";

export async function apiFetchArchiveFile(fileHash: string) {
  const pathSpec = `/file/{file_hash}`;
  const path = `/file/${fileHash}`;

  const result = await apiV2Fetch<IArchiveFile>(pathSpec, "GET", path);

  return result;
}

interface IBody {
  password: string;
}

export async function apiSetArchiveFilePassword(
  archiveHash: string,
  password: string
) {
  const pathSpec = `/file/{file_hash}`;
  const path = `/file/${archiveHash}`;
  const body: IBody = {
    password,
  };

  const result = await apiV2Fetch<string>(pathSpec, "PATCH", path, { body });

  return result;
}
