import { ALL_AUTH_METHODS } from '../auth/types.js';
import { resolveConfig } from '../config/index.js';
import { findDwJson } from '../config/dw-json.js';
import { getLogger } from '../logging/logger.js';
export { ALL_AUTH_METHODS };
export { findDwJson };
/**
 * Loads configuration with precedence: CLI flags/env vars > dw.json > ~/.mobify
 *
 * OCLIF handles environment variables automatically via flag `env` properties.
 * The flags parameter already contains resolved env var values.
 *
 * Uses {@link resolveConfig} internally for consistent behavior across CLI and SDK.
 *
 * @param flags - Configuration values from CLI flags/env vars
 * @param options - Loading options
 * @param pluginSources - Optional sources from CLI plugins (via b2c:config-sources hook)
 * @returns Resolved configuration with factory methods
 *
 * @example
 * ```typescript
 * // In a CLI command
 * const config = loadConfig(
 *   { hostname: this.flags.server, clientId: this.flags['client-id'] },
 *   { instance: this.flags.instance }
 * );
 *
 * if (config.hasB2CInstanceConfig()) {
 *   const instance = config.createB2CInstance();
 * }
 * ```
 */
export function loadConfig(flags = {}, options = {}, pluginSources = {}) {
    const logger = getLogger();
    // Preserve instanceName from options.instance if not already in flags
    const effectiveFlags = {
        ...flags,
        instanceName: flags.instanceName ?? options.instance,
    };
    const resolved = resolveConfig(effectiveFlags, {
        instance: options.instance,
        configPath: options.configPath,
        hostnameProtection: true,
        cloudOrigin: options.cloudOrigin,
        credentialsFile: options.credentialsFile,
        accountManagerHost: options.accountManagerHost,
        sourcesBefore: pluginSources.before,
        sourcesAfter: pluginSources.after,
    });
    // Log source summary
    for (const source of resolved.sources) {
        logger.trace({
            source: source.name,
            location: source.location,
            fields: source.fields,
            fieldsIgnored: source.fieldsIgnored,
        }, `[${source.name}] Contributed fields`);
    }
    // Log warnings
    for (const warning of resolved.warnings) {
        logger.trace({ warning }, `[Config] ${warning.message}`);
    }
    return resolved;
}
//# sourceMappingURL=config.js.map