/**
 * 系统日志 API
 */
import request from '@/api/request'

/**
 * 系统日志项
 */
export interface SystemLog {
  id: number
  level: string // debug, info, warning, error
  type: string // system, user, api, error, security
  user: string | null
  user_id: number | null
  ip: string | null
  message: string
  user_agent: string | null
  path: string | null
  method: string | null
  extra_data: string | null
  created_at: string
  updated_at: string
}

/**
 * 系统日志列表响应
 */
export interface SystemLogListResponse {
  items: SystemLog[]
  total: number
  page: number
  page_size: number
  total_pages: number
}

/**
 * 系统日志查询参数
 */
export interface SystemLogQuery {
  level?: string
  type?: string
  user?: string
  keyword?: string
  start_date?: string
  end_date?: string
  page?: number
  page_size?: number
}

/**
 * 获取系统日志列表
 */
export function getSystemLogs(params: SystemLogQuery) {
  return request.get<SystemLogListResponse>('/api/v1/admin/logs', params)
}

/**
 * 获取日志详情
 */
export function getLogDetail(logId: number) {
  return request.get<SystemLog>(`/api/v1/admin/logs/${logId}`)
}

/**
 * 清理旧日志
 */
export function cleanupOldLogs(beforeDays: number) {
  return request.delete<{ deleted_count: number }>(`/api/v1/admin/logs/cleanup?before_days=${beforeDays}`)
}



