import request from '@/utils/request'

export interface OperationLog {
  id?: number
  username?: string
  operation?: string
  method?: string
  params?: string
  result?: string
  ip?: string
  duration?: number
  status?: string
  errorMsg?: string
  createdAt?: string
}

export interface PageResponse<T> {
  content: T[]
  totalPages: number
  totalElements: number
  currentPage: number
  size: number
}

export const operationLogApi = {
  getAll: () => request.get<OperationLog[]>('/logs/operation'),
  
  getById: (id: number) => request.get<OperationLog>(`/logs/operation/${id}`),
  
  getPage: (params: {
    page?: number
    size?: number
    sort?: string
    order?: string
    keyword?: string
  }) => request.get<PageResponse<OperationLog>>('/logs/operation/page', { params }),
  
  getCount: () => request.get<number>('/logs/operation/count'),
  
  create: (data: Partial<OperationLog>) => request.post<OperationLog>('/logs/operation', data)
}