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

const BASE_URL = '/sys/log'

export async function getLogList(params: { 
  current: number; 
  pageSize: number; 
  method?: string;
  path?: string;
  status?: number;
}) {
  if (USE_MOCK) {
    await delay()
    let list = [...mockLogs]
    if (params.method) list = list.filter(l => l.method === params.method)
    if (params.path) list = list.filter(l => l.path.includes(params.path!))
    if (params.status) list = list.filter(l => l.status === params.status)
    
    return paginate(list, params.current, params.pageSize)
  }
  return post<PageResult<OperationLog>>(`${BASE_URL}/list`, params)
}

export async function deleteLog(ids: string[]) {
  if (USE_MOCK) { await delay(); return null }
  return post<null>(`${BASE_URL}/delete`, { ids })
}
