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

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

const getVariant = async (variantId) => {
  return await fastapiClient.request(`/api/admin/variants/${variantId}`);
};

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

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

export default {
  listVariants,
  getVariant,
  createVariant,
  updateVariant,
};
