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 getCouponList = (params: {
  page?: number;
  pageSize?: number;
  name?: string;
  type?: number;
  status?: number;
}) => {
  return http.request<ResultTable>("get", "/marketing/coupon/list", { params });
};

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

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

export const updateCouponStatus = (id: number, status: number) => {
  return http.request<Result>("put", `/marketing/coupon/${id}/status?status=${status}`);
};

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

export const distributeCoupon = (data: {
  templateId: number;
  targetType: number; // 1-全部用户，3-指定用户
  userIds?: number[];
}) => {
  return http.request<Result>("post", "/marketing/coupon/distribute", { data });
};

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

export const getAvailableCoupons = () => {
  return http.request<Result>("get", "/marketing/coupon/available");
};
