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 getOperationLogList = (params: {
  page?: number;
  pageSize?: number;
  module?: string;
  username?: string;
  status?: number;
  startTime?: string;
  endTime?: string;
}) => {
  return http.request<ResultTable>("get", "/operation-log/list", { params });
};

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

export const deleteOperationLogBatch = (ids: number[]) => {
  return http.request<Result>("delete", "/operation-log/batch", { data: ids });
};

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

export const clearAllOperationLogs = () => {
  return http.request<Result>("delete", "/operation-log/clear");
};

export const clearOperationLogsBefore = (beforeTime: string) => {
  return http.request<Result>(
    "delete",
    `/operation-log/clear-before?beforeTime=${beforeTime}`
  );
};

export const getOperationLogStatistics = () => {
  return http.request<Result>("get", "/operation-log/statistics");
};
