/**
 * Service for interacting with the Connection Management API.
 */

import { requestApi } from '../lib/api';

const API_BASE = '/settings/connections';

// [DEF:getConnections:Function]
/* @PURPOSE: Fetch a list of saved connections.
   @PRE: None.
   @POST: Returns a promise resolving to an array of connections.
*/
/**
 * Fetch a list of saved connections.
 * @returns {Promise<Array>} List of connections.
 */
export async function getConnections() {
    return requestApi(API_BASE);
}
// [/DEF:getConnections:Function]

// [DEF:createConnection:Function]
/* @PURPOSE: Create a new connection configuration.
   @PRE: connectionData must be a valid object.
   @POST: Returns a promise resolving to the created connection.
*/
/**
 * Create a new connection configuration.
 * @param {Object} connectionData - The connection data.
 * @returns {Promise<Object>} The created connection instance.
 */
export async function createConnection(connectionData) {
    return requestApi(API_BASE, 'POST', connectionData);
}
// [/DEF:createConnection:Function]

// [DEF:deleteConnection:Function]
/* @PURPOSE: Delete a connection configuration.
   @PRE: connectionId must be a valid string.
   @POST: Returns a promise that resolves when deletion is complete.
*/
/**
 * Delete a connection configuration.
 * @param {string} connectionId - The ID of the connection to delete.
 */
export async function deleteConnection(connectionId) {
    return requestApi(`${API_BASE}/${connectionId}`, 'DELETE');
}
// [/DEF:deleteConnection:Function]