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

export const creatorApi = {
  apply: (data) => request("/creator/apply", { method: "POST", body: data }),
  getDashboard: () => request("/creator/dashboard"),
  listContents: (params) => {
    const qs = new URLSearchParams(params).toString();
    return request(`/creator/contents?${qs}`);
  },
  getContent: (id) => request(`/creator/contents/${id}`),
  createContent: (data) =>
    request("/creator/contents", { method: "POST", body: data }),
  updateContent: (id, data) =>
    request(`/creator/contents/${id}`, { method: "PUT", body: data }),
  deleteContent: (id) =>
    request(`/creator/contents/${id}`, { method: "DELETE" }),
  listOrders: (params) => {
    const qs = new URLSearchParams(params).toString();
    return request(`/creator/orders?${qs}`);
  },
  refundOrder: (id, data) =>
    request(`/creator/orders/${id}/refund`, { method: "POST", body: data }),
  listCoupons: (params) => {
    const qs = new URLSearchParams(params).toString();
    return request(`/creator/coupons?${qs}`);
  },
  getCoupon: (id) => request(`/creator/coupons/${id}`),
  createCoupon: (data) =>
    request("/creator/coupons", { method: "POST", body: data }),
  updateCoupon: (id, data) =>
    request(`/creator/coupons/${id}`, { method: "PUT", body: data }),
  grantCoupon: (id, data) =>
    request(`/creator/coupons/${id}/grant`, { method: "POST", body: data }),
  getSettings: () => request("/creator/settings"),
  updateSettings: (data) =>
    request("/creator/settings", { method: "PUT", body: data }),
  listPayoutAccounts: () => request("/creator/payout-accounts"),
  addPayoutAccount: (data) =>
    request("/creator/payout-accounts", { method: "POST", body: data }),
  removePayoutAccount: (id) =>
    request(`/creator/payout-accounts?id=${id}`, { method: "DELETE" }),
  withdraw: (data) =>
    request("/creator/withdraw", { method: "POST", body: data }),
};
