import { apiClient } from './client';

export interface AuditLogEntry {
  id: string;
  userId: string | null;
  tenantId: string | null;
  action: string;
  entityType: string | null;
  entityId: string | null;
  metadata: Record<string, any> | null;
  createdAt: string;
  user: { id: string; email: string; nombre: string } | null;
  tenant: { id: string; nombre: string; rfc: string } | null;
}

export interface AuditLogFilters {
  action?: string;
  tenantId?: string;
  userId?: string;
  from?: string;
  to?: string;
  page?: number;
  limit?: number;
}

export interface AuditLogResponse {
  data: AuditLogEntry[];
  page: number;
  limit: number;
  total: number;
  totalPages: number;
}

export async function listAuditLog(filters: AuditLogFilters = {}): Promise<AuditLogResponse> {
  const response = await apiClient.get<AuditLogResponse>('/audit-log', { params: filters });
  return response.data;
}
