import { http } from "@/utils/http";

type Result = {
  code: number;
  message: string;
  data?: any;
};

type ResultTable = {
  code: number;
  message: string;
  data?: {
    list: Array<any>;
    total: number;
    pageSize: number;
    currentPage: number;
  };
};

// ==================== 分销员管理 ====================

export const createDistributor = (data: object) => {
  return http.request<Result>("post", "/distribution/distributor", { data });
};

export const updateDistributor = (data: object) => {
  return http.request<Result>("put", "/distribution/distributor", { data });
};

export const getDistributorList = (params: object) => {
  return http.request<ResultTable>("get", "/distribution/distributor/list", { params });
};

export const getDistributorDetail = (id: string) => {
  return http.request<Result>("get", `/distribution/distributor/${id}`);
};

export const activateDistributor = (id: string) => {
  return http.request<Result>("put", `/distribution/distributor/${id}/activate`);
};

export const deactivateDistributor = (id: string) => {
  return http.request<Result>("put", `/distribution/distributor/${id}/deactivate`);
};

export const deleteDistributor = (id: string) => {
  return http.request<Result>("delete", `/distribution/distributor/${id}`);
};

export const generateQrcode = (id: string) => {
  return http.request<Result>("post", `/distribution/distributor/${id}/qrcode`);
};

// ==================== 推荐记录 ====================

export const getReferralList = (params: object) => {
  return http.request<ResultTable>("get", "/distribution/referral/list", { params });
};

// ==================== 佣金记录 ====================

export const getCommissionList = (params: object) => {
  return http.request<ResultTable>("get", "/distribution/commission/list", { params });
};

// ==================== 提现管理 ====================

export const getWithdrawalList = (params: object) => {
  return http.request<ResultTable>("get", "/distribution/withdrawal/list", { params });
};

export const reviewWithdrawal = (data: object) => {
  return http.request<Result>("put", "/distribution/withdrawal/review", { data });
};

export const confirmTransfer = (id: string) => {
  return http.request<Result>("put", `/distribution/withdrawal/${id}/confirm`);
};

// ==================== 报表 ====================

export const getReportList = (params: object) => {
  return http.request<ResultTable>("get", "/distribution/report/list", { params });
};

export const generateReport = (yearMonth: string) => {
  return http.request<Result>("post", "/distribution/report/generate", { params: { yearMonth } });
};

export const exportReport = (yearMonth: string) => {
  return http.request<Result>("get", "/distribution/report/export", { params: { yearMonth } });
};

// ==================== 仪表盘 ====================

export const getDashboard = () => {
  return http.request<Result>("get", "/distribution/dashboard");
};

// ==================== 配置 ====================

export const getConfigList = () => {
  return http.request<Result>("get", "/distribution/config/list");
};

export const updateConfig = (data: object) => {
  return http.request<Result>("put", "/distribution/config", { data });
};
