/**
 * KRA - Operation Record API Service
 */
import request from '@/utils/request';

export interface OperationRecord {
  ID?: number;
  CreatedAt?: string;
  ip: string;
  method: string;
  path: string;
  status: number;
  latency: string;
  agent: string;
  error_message?: string;
  body?: string;
  resp?: string;
  user_id: number;
  user?: {
    userName: string;
    nickName: string;
  };
}

export interface OperationRecordSearchParams {
  page?: number;
  pageSize?: number;
  path?: string;
  method?: string;
  status?: number;
  user_id?: number;
}

/** 删除操作记录 */
export const deleteSysOperationRecord = (data: { ID: number }) => {
  return request.delete('/sysOperationRecord/deleteSysOperationRecord', { data });
};

/** 批量删除操作记录 */
export const deleteSysOperationRecordByIds = (data: { ids: number[] }) => {
  return request.delete('/sysOperationRecord/deleteSysOperationRecordByIds', { data });
};

/** 分页获取操作记录列表 */
export const getSysOperationRecordList = (params: OperationRecordSearchParams) => {
  return request.get('/sysOperationRecord/getSysOperationRecordList', { params });
};

// 别名导出，兼容页面调用
export const getOperationRecordList = getSysOperationRecordList;
export const deleteOperationRecord = deleteSysOperationRecord;
export const deleteOperationRecordByIds = deleteSysOperationRecordByIds;

export default {
  deleteSysOperationRecord,
  deleteSysOperationRecordByIds,
  getSysOperationRecordList,
  getOperationRecordList,
  deleteOperationRecord,
  deleteOperationRecordByIds,
};
