import request from "@/utils/request";

/**
 * 获取所有单页
 * @returns {Promise}
 */
export function getOnePages() {
  return request({
    url: "/backend/allonepages",
    method: "get",
  });
}

/**
 * 创建单页
 * @param {Object} onePageData 单页数据
 * @returns {Promise}
 */
export function createOnePage(formData) {
  return request({
    url: "/backend/createonepage",
    method: "post",
    data: formData,
  });
}

/**
 * 编辑单页
 * @param {number|string} id 单页ID
 * @param {Object} onePageData 更新的数据
 * @returns {Promise}
 */
export function editOnePage(id, onePageData) {
  return request({
    url: `/backend/editonepage/${id}`,
    method: "post",
    data: onePageData,
  });
}

/**
 * 删除单页
 * @param {number|string} id 单页ID
 * @returns {Promise}
 */
export function deleteOnePage(id) {
  return request({
    url: `/backend/deleteonepage/${id}`,
    method: "delete",
  });
}

/**
 * 根据路径获取单页（前端使用）
 * @param {string} path 路由路径
 * @returns {Promise}
 */
export function getOnePageByPath(path) {
  return request({
    url: `/index/onepage/${encodeURIComponent(path)}`,
    method: "get",
  });
}

