import client from './client';
import type { PaginatedResponse } from './types';

export interface AuditLogItem {
  id: string;
  tenant_id: string;
  action: string;
  resource_type: string;
  resource_id: string;
  user_id: string;
  old_value?: string;
  new_value?: string;
  ip_address?: string;
  user_agent?: string;
  created_at: string;
}

export interface AuditLogQuery {
  resource_type?: string;
  user_id?: string;
  page?: number;
  page_size?: number;
}

export async function listAuditLogs(query: AuditLogQuery = {}) {
  const { data } = await client.get<{ success: boolean; data: PaginatedResponse<AuditLogItem> }>(
    '/audit-logs',
    { params: { page: query.page ?? 1, page_size: query.page_size ?? 20, ...query } },
  );
  return data.data;
}
