import { get } from '@/lib/request'
import { USE_MOCK, delay, paginate, mockResponse } from '@/mock'
import { mockLogs } from '@/mock/system/logs'
import type { OperationLog } from '../system'

export async function getLogList(params: { 
  current: number; 
  pageSize: number; 
  operatorName?: string; 
  clientId?: string;
  path?: string;
  status?: number;
}) {
  if (USE_MOCK) {
    await delay()
    let list = [...mockLogs]
    if (params.operatorName) list = list.filter(l => l.operatorName?.includes(params.operatorName!))
    if (params.clientId && params.clientId !== 'all') list = list.filter(l => l.clientId === params.clientId)
    if (params.path) list = list.filter(l => l.path.includes(params.path!))
    if (params.status) list = list.filter(l => l.statusCode === params.status)
    
    return mockResponse(paginate(list, params.current, params.pageSize))
  }
  return get<{ code: number; data: { list: OperationLog[]; total: number }; msg: string }>('/system/logs', params)
}
