const host = "";

export async function fetchArticleList(type: number, page: number, size: number) {
  const formData = new FormData();
  formData.append("type", type.toString());
  formData.append("page", page.toString());
  formData.append("size", size.toString());

  const result = await fetch(`${host}/api/v1/cms/listArticle`, {
    method: "POST",
    body: formData,
    cache: "no-store",
  });
  const json = await result.json();
  return json;
}

export async function fetchArticleDetail(id: number) {
  const formData = new FormData();
  formData.append("id", id.toString());

  const result = await fetch(`${host}/api/v1/cms/articleDetail`, {
    method: "POST",
    body: formData,
  });
  const json = await result.json();
  return json;
}

export async function buyArticle(id: number) {
  const formData = new FormData();
  formData.append("articleId", id.toString());

  const result = await fetch(`${host}/api/v1/order/buyArticle`, {
    method: "POST",
    body: formData,
  });
  const json = await result.json();
  return json;
}
