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 getInviteActivityList = (params: any) => {
  return http.request<ResultTable>("get", "/marketing/invite/activity/list", { params });
};

export const getInviteActivityDetail = (id: number) => {
  return http.request<Result>("get", `/marketing/invite/activity/${id}`);
};

export const createInviteActivity = (data: any) => {
  return http.request<Result>("post", "/marketing/invite/activity", { data });
};

export const updateInviteActivity = (id: number, data: any) => {
  return http.request<Result>("put", `/marketing/invite/activity/${id}`, { data });
};

export const publishInviteActivity = (id: number) => {
  return http.request<Result>("put", `/marketing/invite/activity/${id}/publish`);
};

export const pauseInviteActivity = (id: number) => {
  return http.request<Result>("put", `/marketing/invite/activity/${id}/pause`);
};

export const resumeInviteActivity = (id: number) => {
  return http.request<Result>("put", `/marketing/invite/activity/${id}/resume`);
};

export const deleteInviteActivity = (id: number) => {
  return http.request<Result>("delete", `/marketing/invite/activity/${id}`);
};

// ==================== 数据统计 ====================

export const getInviteStatistics = (activityId: number, params?: any) => {
  return http.request<Result>("get", `/marketing/invite/statistics/${activityId}`, { params });
};

// ==================== 邀请记录管理 ====================

export const getInviteRecords = (params: any) => {
  return http.request<ResultTable>("get", "/marketing/invite/records", { params });
};

export const exportInviteRecords = (params: any) => {
  return http.request<Result>("get", "/marketing/invite/records/export", {
    params,
    responseType: "blob"
  });
};

// ==================== 奖励管理 ====================

export const manualReissueReward = (rewardId: number) => {
  return http.request<Result>("post", "/marketing/invite/reward/manual-reissue", {
    params: { rewardId }
  });
};
