import request from '@/utils/request'

export interface ExceptionLog {
  id?: number
  username?: string
  operation?: string
  method?: string
  params?: string
  errorMsg?: string
  exceptionStack?: string
  ip?: string
  createTime?: string
}

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

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