import fastapiClient from "@/services/api/fastapi-client";

const listReleases = async ({ experimentId } = {}) => {
  const query = experimentId
    ? `?experiment_id=${encodeURIComponent(experimentId)}`
    : "";
  const response = await fastapiClient.request(`/api/admin/releases${query}`);
  return response.items || [];
};

const getRelease = async (releaseId) => {
  return await fastapiClient.request(`/api/admin/releases/${releaseId}`);
};

const buildRelease = async (experimentId) => {
  return await fastapiClient.request("/api/admin/releases/build", {
    method: "POST",
    body: JSON.stringify({ experiment_id: experimentId }),
  });
};

const publishRelease = async (releaseId) => {
  return await fastapiClient.request(`/api/admin/releases/${releaseId}/publish`, {
    method: "POST",
  });
};

const rollbackRelease = async (releaseId) => {
  return await fastapiClient.request(`/api/admin/releases/${releaseId}/rollback`, {
    method: "POST",
  });
};

const archiveRelease = async (releaseId) => {
  return await fastapiClient.request(`/api/admin/releases/${releaseId}/archive`, {
    method: "POST",
  });
};

export default {
  listReleases,
  getRelease,
  buildRelease,
  publishRelease,
  rollbackRelease,
  archiveRelease,
};
