import { useQuery } from '@tanstack/react-query'
import api from '@/services/api'
import type { AuditLogEntry } from '@/types'

export interface AuditLogFilters {
  skip: number
  limit: number
  user_id?: string
  action?: string
  date_from?: string
  date_to?: string
}

export function useAuditLog(filters: AuditLogFilters) {
  const params: Record<string, string | number> = {
    skip: filters.skip,
    limit: filters.limit,
  }
  if (filters.user_id) params.user_id = filters.user_id
  if (filters.action) params.action = filters.action
  if (filters.date_from) params.date_from = filters.date_from
  if (filters.date_to) params.date_to = filters.date_to

  return useQuery({
    queryKey: ['audit-log', params],
    queryFn: () => api.get<AuditLogEntry[]>('/admin/audit-log', { params }).then(r => r.data),
  })
}
