import { get } from '@/lib/http/client'
import type { OperationLogListParams, OperationLogListResponse } from '@/types/operation-log'

interface BackendListResponse<T> {
  list: T[]
  total: number
  page: number
  size: number
}

export async function listOperationLogs(params?: OperationLogListParams): Promise<OperationLogListResponse> {
  const result = await get<BackendListResponse<OperationLogListResponse['items'][number]>>(
    '/logs/operation',
    params as Record<string, string | number | boolean | undefined>,
  )

  return {
    items: result.list,
    total: result.total,
    page: result.page,
    page_size: result.size,
  }
}

export async function listMyOperationLogs(
  params?: Pick<OperationLogListParams, 'page' | 'page_size'>,
): Promise<OperationLogListResponse> {
  const result = await get<BackendListResponse<OperationLogListResponse['items'][number]>>(
    '/logs/operation/me',
    params as Record<string, string | number | boolean | undefined>,
  )

  return {
    items: result.list,
    total: result.total,
    page: result.page,
    page_size: result.size,
  }
}
