/**
 * Integrations API service
 *
 * Handles all API calls related to integration management.
 * Uses the integration factory for consistent service generation.
 *
 * Usage:
 * - Use getIntegrationService(slug) for connect/disconnect/status operations
 * - Use getIntegrations() to list all integrations with their status
 * - Use service.getDataForConnection() for integration-specific data (lists, databases, etc.)
 *
 * @example
 * ```ts
 * // Connect to an integration
 * const service = getIntegrationService('mailchimp');
 * const conn = await service.createConnection('Main', { api_key: 'xxx' });
 *
 * // Fetch integration-specific data
 * const lists = await service.getDataForConnection<MCList[]>(conn.connection_id, 'lists');
 * ```
 */

import { apiRequest } from './api';
import { Integration } from '../types/integration';

import { getIntegrationService, getIntegrationMetadata } from './integrationFactory';

import type { CredentialConfig } from './integrationFactory';

// Re-export factory utilities for consumers
export { getIntegrationService, getIntegrationMetadata };

export type { CredentialConfig };

/**
 * Get all available integrations with their connection status.
 */
export async function getIntegrations(): Promise<Integration[]> {
  return apiRequest<Integration[]>('/integrations');
}
