/**
 * 优惠券管理 API
 */

import { get, post, put, del } from '@/utils/request';

export interface CouponQueryParams {
  page?: number;
  pageSize?: number;
  name?: string;
  type?: number;
  status?: number;
}

export interface CouponListResponse {
  list: any[];
  total: number;
  pageSize: number;
  currentPage: number;
}

/** 获取优惠券列表 */
export function getCouponList(params: CouponQueryParams): Promise<CouponListResponse> {
  return get('/marketing/coupon/list', params);
}

/** 获取优惠券详情 */
export function getCouponById(id: number): Promise<any> {
  return get(`/marketing/coupon/${id}`);
}

/** 创建优惠券 */
export function createCoupon(data: any): Promise<any> {
  return post('/marketing/coupon', data);
}

/** 更新优惠券状态 */
export function updateCouponStatus(id: number, status: number): Promise<any> {
  return put(`/marketing/coupon/${id}/status?status=${status}`);
}

/** 删除优惠券 */
export function deleteCoupon(id: number): Promise<any> {
  return del(`/marketing/coupon/${id}`);
}

/** 发放优惠券 */
export function distributeCoupon(data: {
  templateId: number;
  targetType: number;
  userIds?: number[];
}): Promise<any> {
  return post('/marketing/coupon/distribute', data);
}

/** 获取优惠券统计 */
export function getCouponStatistics(id: number): Promise<any> {
  return get(`/marketing/coupon/${id}/statistics`);
}

/** 获取可用优惠券列表（下拉选择用） */
export function getAvailableCoupons(): Promise<any[]> {
  return get('/marketing/coupon/available');
}
