import { request } from "../utils/request";

export const contentApi = {
  list: (params) => {
    if (params.tenant_id) {
      const { tenant_id: tenantID, ...rest } = params;
      const qs = new URLSearchParams(rest).toString();
      return request(`/creators/${tenantID}/contents?${qs}`);
    }
    const qs = new URLSearchParams(params).toString();
    return request(`/contents?${qs}`);
  },
  get: (id) => request(`/contents/${id}`),
  listComments: (id, page) =>
    request(`/contents/${id}/comments?page=${page || 1}`),
  createComment: (id, data) =>
    request(`/contents/${id}/comments`, { method: "POST", body: data }),
  likeComment: (id) => request(`/comments/${id}/like`, { method: "POST" }),
  addLike: (id) => request(`/contents/${id}/like`, { method: "POST" }),
  removeLike: (id) => request(`/contents/${id}/like`, { method: "DELETE" }),
  addFavorite: (id) => request(`/contents/${id}/favorite`, { method: "POST" }),
  removeFavorite: (id) =>
    request(`/contents/${id}/favorite`, { method: "DELETE" }),
  listTopics: () => request("/topics"),
};
