// ⚠ Mock 数据，后续请替换成真实接口。
import mockStore from "../stores/useMockData.js";

// 模拟网络延迟
const delay = (ms = 500) => new Promise((resolve) => setTimeout(resolve, ms));

export const api = {
  // 文章分类接口
  async getCategories() {
    await delay();
    return { code: 200, data: mockStore.mockCategories, msg: "success" };
  },
  async addCategory(data) {
    await delay();
    mockStore.addCategory(data);
    return { code: 200, data: null, msg: "success" };
  },
  async updateCategory(id, data) {
    await delay();
    mockStore.updateCategory(id, data);
    return { code: 200, data: null, msg: "success" };
  },

  // 文章接口
  async getArticles(page = 1, pageSize = 10) {
    await delay();
    const total = mockStore.mockArticles.length;
    const start = (page - 1) * pageSize;
    const data = mockStore.mockArticles.slice(start, start + pageSize);
    return { code: 200, data: { list: data, total }, msg: "success" };
  },
  async addArticle(data) {
    await delay();
    mockStore.addArticle(data);
    return { code: 200, data: null, msg: "success" };
  },
  async updateArticle(id, data) {
    await delay();
    mockStore.updateArticle(id, data);
    return { code: 200, data: null, msg: "success" };
  },
};
