// 文章管理相关API
import request from "@/utils/request";

// 获取文章列表
export function listArticles(params) {
  return request({
    url: `/platform/articlesList`,
    method: "get",
    params,
  });
}

// 获取文章所有文章
export function listAllArticles(params) {
  return request({
    url: `/platform/allarticles`,
    method: "get",
    params,
  });
}

// 获取文章详情
export function getArticle(id) {
  return request({
    url: `/platform/articles/${id}`,
    method: "get",
  });
}

// 创建文章
export function createArticle(data) {
  return request({
    url: '/platform/createarticle',
    method: 'post',
    data,
  });
}

// 编辑文章
export function editArticle(id, data) {
  return request({
    url: `/platform/editarticle/${id}`,
    method: 'post',
    data,
  });
}

// 删除文章
export function deleteArticle(id) {
  return request({
    url: `/platform/deletearticle/${id}`,
    method: "delete",
  });
}

// 发布文章
export function publishArticle(id,uid) {
  return request({
    url: `/platform/publisharticle/${id}`,
    method: 'post',
    data: {
      uid
    } 
  });
}

// 下架文章
export function unPublishArticle(id) {
  return request({
    url: `/platform/unPublisharticle/${id}`,
    method: 'post'
  });
}

// 文章推荐
export function articleRecommend(id) {
  return request({
    url: `/platform/articleRecommend/${id}`,
    method: 'post'
  });
}

// 取消文章推荐
export function unArticleRecommend(id) {
  return request({
    url: `/platform/unArticleRecommend/${id}`,
    method: 'post'
  });
}

// 文章置顶
export function articleTop(id) {
  return request({
    url: `/platform/articleTop/${id}`,
    method: 'post'
  });
}

// 取消文章置顶
export function unArticleTop(id) {
  return request({
    url: `/platform/unArticleTop/${id}`,
    method: 'post'
  });
}



////////////////////////////分类相关////////////////////////////

// 获取所有分类列表
export function allCategories(params) {
  return request({
    url: `/platform/allcategories`,
    method: "get",
    params,
  });
}

// 获取分类列表
export function listCategories(params) {
  return request({
    url: `/platform/categories`,
    method: "get",
    params,
  });
}

// 获取分类详情
export function getCategory(id) {
  return request({
    url: `/platform/categories/${id}`,
    method: "get",
  });
}

// 创建分类
export function createCategory(data) {
  return request({
    url: `/platform/createCategory`,
    method: "post",
    data,
  });
}

// 更新分类
export function editCategory(id, data) {
  return request({
    url: `/platform/editCategory/${id}`,
    method: "post",
    data,
  });
}

// 删除分类
export function deleteCategory(id) {
  return request({
    url: `/platform/categories/${id}`,
    method: "delete",
  });
}

// 更新分类状态
export function updateCategoryStatus(id, status) {
  return request({
    url: `/platform/categories/${id}/status`,
    method: "patch",
    data: { status },
  });
}