/**
 * 定时折扣管理 API
 */

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

export interface TimedDiscountQueryParams {
  page?: number;
  pageSize?: number;
  activityName?: string;
  status?: number;
  discountType?: number;
}

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

/** 获取定时折扣列表 */
export function getTimedDiscountList(params: TimedDiscountQueryParams): Promise<TimedDiscountListResponse> {
  return get('/timed-discount/list', params);
}

/** 获取定时折扣详情 */
export function getTimedDiscountById(id: number): Promise<any> {
  return get(`/timed-discount/${id}`);
}

/** 创建定时折扣 */
export function createTimedDiscount(data: any): Promise<any> {
  return post('/timed-discount', data);
}

/** 更新定时折扣 */
export function updateTimedDiscount(id: number, data: any): Promise<any> {
  return put(`/timed-discount/${id}`, data);
}

/** 更新状态 */
export function updateTimedDiscountStatus(id: number, status: number): Promise<any> {
  return put(`/timed-discount/${id}/status`, { status });
}

/** 删除定时折扣 */
export function deleteTimedDiscount(id: number): Promise<any> {
  return del(`/timed-discount/${id}`);
}

/** 执行定时折扣 */
export function executeTimedDiscount(id: number): Promise<any> {
  return post(`/timed-discount/${id}/execute`);
}

/** 获取执行记录 */
export function getTimedDiscountRecords(params: {
  page?: number;
  pageSize?: number;
  activityId?: number;
  executeDateStart?: string;
  executeDateEnd?: string;
  shopId?: number;
  deviceId?: string;
  status?: number;
}): Promise<TimedDiscountListResponse> {
  return get('/timed-discount/records', params);
}

/** 获取定时折扣统计 */
export function getTimedDiscountStatistics(id: number): Promise<any> {
  return get(`/timed-discount/${id}/statistics`);
}
