/*
 * Copyright (c) 2025, Salesforce, Inc.
 * SPDX-License-Identifier: Apache-2
 * For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
 */
/**
 * SLAS Admin API client for B2C Commerce.
 *
 * Provides a fully typed client for SLAS Admin API operations using
 * openapi-fetch with OAuth authentication middleware. Used for
 * administration tasks like managing tenants and SLAS clients.
 *
 * @module clients/slas-admin
 */
import createClient from 'openapi-fetch';
import { createAuthMiddleware, createLoggingMiddleware } from './middleware.js';
import { globalMiddlewareRegistry } from './middleware-registry.js';
/**
 * Creates a typed SLAS Admin API client.
 *
 * Returns the openapi-fetch client directly, with authentication
 * handled via middleware. This gives full access to all openapi-fetch
 * features with type-safe paths, parameters, and responses.
 *
 * @param config - SLAS client configuration
 * @param auth - Authentication strategy (typically OAuth)
 * @returns Typed openapi-fetch client
 *
 * @example
 * // Create SLAS client with OAuth auth
 * const oauthStrategy = new OAuthStrategy({
 *   clientId: 'your-client-id',
 *   clientSecret: 'your-client-secret',
 *   scopes: ['SLAS_ORGANIZATION_ADMIN']
 * });
 *
 * const client = createSlasClient(
 *   { shortCode: 'kv7kzm78' },
 *   oauthStrategy
 * );
 *
 * // Create or update a SLAS client
 * const { data, error } = await client.PUT('/tenants/{tenantId}/clients/{clientId}', {
 *   params: {
 *     path: { tenantId: 'your-tenant', clientId: 'new-client-id' }
 *   },
 *   body: {
 *     clientId: 'new-client-id',
 *     name: 'My SLAS Client',
 *     channels: ['RefArch'],
 *     scopes: ['sfcc.products', 'sfcc.catalogs'],
 *     redirectUri: ['http://localhost:3000/callback'],
 *     secret: '',
 *     isPrivateClient: true
 *   }
 * });
 *
 * @example
 * // List all clients for a tenant
 * const { data, error } = await client.GET('/tenants/{tenantId}/clients', {
 *   params: { path: { tenantId: 'your-tenant' } }
 * });
 */
export function createSlasClient(config, auth) {
    const registry = config.middlewareRegistry ?? globalMiddlewareRegistry;
    const client = createClient({
        baseUrl: `https://${config.shortCode}.api.commercecloud.salesforce.com/shopper/auth-admin/v1`,
    });
    // Core middleware: auth first
    client.use(createAuthMiddleware(auth));
    // Plugin middleware from registry
    for (const middleware of registry.getMiddleware('slas')) {
        client.use(middleware);
    }
    // Logging middleware last (sees complete request with all modifications)
    client.use(createLoggingMiddleware('SLAS'));
    return client;
}
//# sourceMappingURL=slas-admin.js.map