// Activity log service layer

import { apiRequest } from './api';
import { ActivityLog } from '../types/activity';

interface GetActivityLogsFilters {
  workflow_id?: number;
  level?: string;
  limit?: number;
  offset?: number;
  start_date?: string;
  end_date?: string;
}

/**
 * Get activity logs with optional filters
 */
export async function getActivityLogs(filters?: GetActivityLogsFilters): Promise<ActivityLog[]> {
  // Build query string from filters
  const params = new URLSearchParams();
  if (filters?.workflow_id) params.append('workflow_id', filters.workflow_id.toString());
  if (filters?.level) params.append('level', filters.level);
  if (filters?.limit) params.append('limit', filters.limit.toString());
  if (filters?.offset) params.append('offset', filters.offset.toString());
  if (filters?.start_date) params.append('start_date', filters.start_date);
  if (filters?.end_date) params.append('end_date', filters.end_date);

  const queryString = params.toString();
  const endpoint = queryString ? `/activity?${queryString}` : '/activity';

  return apiRequest<ActivityLog[]>(endpoint, { method: 'GET' });
}

// Export as a service object
export const activityService = {
  getActivityLogs,
};
