import request from './request'

export interface OperationLog {
  id: number
  username: string
  operation: string
  method: string
  params: string | null
  result: string | null
  ip: string
  duration: number
  status: string
  errorMsg: string | null
  createBy: string | null
  updateBy: string | null
  createdAt: string
  updatedAt: string
  deletedAt: string | null
}

export interface OperationLogPageResponse {
  content: OperationLog[]
  totalPages: number
  totalElements: number
  currentPage: number
  pageSize: number
  first: boolean
  last: boolean
}

export function getOperationLogs(params?: {
  page?: number
  size?: number
  sort?: string
  order?: string
  keyword?: string
  username?: string
  operation?: string
  status?: string
  startTime?: string
  endTime?: string
  ip?: string
  method?: string
}): Promise<OperationLogPageResponse> {
  return request.get('/api/logs/operation/page', { params })
}

export function getOperationLogCount(): Promise<number> {
  return request.get('/api/logs/operation/count')
}

export function exportOperationLogs(params?: {
  username?: string
  operation?: string
  status?: string
  startTime?: string
  endTime?: string
  ip?: string
  method?: string
  keyword?: string
}): Promise<Blob> {
  return request.get('/api/logs/operation/export', {
    params,
    responseType: 'blob',
  })
}
