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

const listExperiments = async () => {
  const response = await fastapiClient.request("/api/admin/experiments");
  return response.items || [];
};

const getExperiment = async (experimentId) => {
  return await fastapiClient.request(`/api/admin/experiments/${experimentId}`);
};

const createExperiment = async (data) => {
  return await fastapiClient.request("/api/admin/experiments", {
    method: "POST",
    body: JSON.stringify(data),
  });
};

const updateExperiment = async (experimentId, data) => {
  return await fastapiClient.request(`/api/admin/experiments/${experimentId}`, {
    method: "PATCH",
    body: JSON.stringify(data),
  });
};

const listGoals = async ({ siteId } = {}) => {
  const query = siteId ? `?site_id=${encodeURIComponent(siteId)}` : "";
  const response = await fastapiClient.request(`/api/admin/goals${query}`);
  return response.items || [];
};

const listActivity = async (experimentId) => {
  const response = await fastapiClient.request(`/api/admin/experiments/${experimentId}/activity`);
  return response.items || [];
};

export default {
  listExperiments,
  getExperiment,
  createExperiment,
  updateExperiment,
  listGoals,
  listActivity,
};
