import { request, type ApiResponse, type PagedResult } from '@/utils/request'

export interface OperationLog {
  id: number
  userId: number
  username: string
  module: string
  action: string
  method: string
  url: string
  params: string | null
  ip: string | null
  userAgent: string | null
  duration: number
  status: number
  errorMessage: string | null
  createdAt: string
}

export interface OperationLogQuery {
  keyword?: string
  module?: string
  startDate?: string
  endDate?: string
  page: number
  pageSize: number
}

// 获取操作日志列表
export function getOperationLogList(params: OperationLogQuery): Promise<ApiResponse<PagedResult<OperationLog>>> {
  return request({
    url: '/admin/logs',
    method: 'get',
    params
  })
}

// 获取操作日志详情
export function getOperationLog(id: number): Promise<ApiResponse<OperationLog>> {
  return request({
    url: `/admin/logs/${id}`,
    method: 'get'
  })
}
