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

const createEditorSession = async (payload) => {
  return await fastapiClient.request("/api/editor/sessions", {
    method: "POST",
    body: JSON.stringify(payload),
  });
};

const getVariantChanges = async (variantId) => {
  const response = await fastapiClient.request(
    `/api/editor/variants/${variantId}/changes`
  );
  return response.items || [];
};

const saveVariantChanges = async (variantId, items) => {
  const response = await fastapiClient.request(
    `/api/editor/variants/${variantId}/changes`,
    {
      method: "PUT",
      body: JSON.stringify({ items }),
    }
  );
  return response.items || [];
};

const buildPreview = async (payload) => {
  return await fastapiClient.request("/api/editor/previews/build", {
    method: "POST",
    body: JSON.stringify(payload),
  });
};

export default {
  createEditorSession,
  getVariantChanges,
  saveVariantChanges,
  buildPreview,
};
