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 getTimedDiscountList = (params?: {
  page?: number;
  pageSize?: number;
  activityName?: string;
  status?: number;
  discountType?: number;
}) => {
  return http.request<ResultTable>("get", "/timed-discount/list", { params });
};

export const getTimedDiscountById = (id: number) => {
  return http.request<Result>("get", `/timed-discount/${id}`);
};

export const createTimedDiscount = (data: any) => {
  return http.request<Result>("post", "/timed-discount", { data });
};

export const updateTimedDiscount = (id: number, data: any) => {
  return http.request<Result>("put", `/timed-discount/${id}`, { data });
};

export const updateTimedDiscountStatus = (id: number, status: number) => {
  return http.request<Result>("put", `/timed-discount/${id}/status`, { params: { status } });
};

export const deleteTimedDiscount = (id: number) => {
  return http.request<Result>("delete", `/timed-discount/${id}`);
};

export const executeTimedDiscount = (id: number) => {
  return http.request<Result>("post", `/timed-discount/${id}/execute`);
};

export const getTimedDiscountRecords = (params?: {
  page?: number;
  pageSize?: number;
  activityId?: number;
  executeDateStart?: string;
  executeDateEnd?: string;
  shopId?: number;
  deviceId?: string;
  status?: number;
}) => {
  return http.request<ResultTable>("get", "/timed-discount/records", { params });
};

export const getTimedDiscountRecordById = (recordId: number) => {
  return http.request<Result>("get", `/timed-discount/records/${recordId}`);
};

export const getPriceAdjustmentLogs = (recordId: number, params?: {
  page?: number;
  pageSize?: number;
}) => {
  return http.request<ResultTable>("get", `/timed-discount/records/${recordId}/logs`, { params });
};

export const getTimedDiscountStatistics = (id: number) => {
  return http.request<Result>("get", `/timed-discount/${id}/statistics`);
};

export const getTimedDiscountDailyStatistics = (id: number, params?: {
  page?: number;
  pageSize?: number;
}) => {
  return http.request<ResultTable>("get", `/timed-discount/${id}/statistics/daily`, { params });
};

export const getEnabledTimedDiscounts = () => {
  return http.request<Result>("get", "/timed-discount/enabled");
};
