import { BasicAuthStrategy } from '../auth/basic.js';
import { ApiKeyStrategy } from '../auth/api-key.js';
import { resolveAuthStrategy } from '../auth/resolve.js';
import { createInstanceFromConfig } from './mapping.js';
/**
 * Implementation of ResolvedB2CConfig.
 *
 * Provides validation methods and factory methods for creating SDK objects
 * from resolved configuration.
 */
export class ResolvedConfigImpl {
    values;
    warnings;
    sources;
    constructor(values, warnings, sources) {
        this.values = values;
        this.warnings = warnings;
        this.sources = sources;
    }
    // Validation methods
    hasB2CInstanceConfig() {
        return Boolean(this.values.hostname);
    }
    hasMrtConfig() {
        return Boolean(this.values.mrtApiKey);
    }
    hasOAuthConfig() {
        return Boolean(this.values.clientId);
    }
    hasBasicAuthConfig() {
        return Boolean(this.values.username && this.values.password);
    }
    // Factory methods
    createB2CInstance() {
        if (!this.hasB2CInstanceConfig()) {
            throw new Error('B2C instance requires hostname');
        }
        return createInstanceFromConfig(this.values);
    }
    createBasicAuth() {
        if (!this.hasBasicAuthConfig()) {
            throw new Error('Basic auth requires username and password');
        }
        return new BasicAuthStrategy(this.values.username, this.values.password);
    }
    createOAuth(options) {
        if (!this.hasOAuthConfig()) {
            throw new Error('OAuth requires clientId');
        }
        const credentials = {
            clientId: this.values.clientId,
            clientSecret: this.values.clientSecret,
            scopes: this.values.scopes,
            accountManagerHost: this.values.accountManagerHost,
        };
        return resolveAuthStrategy(credentials, { allowedMethods: options?.allowedMethods });
    }
    createMrtAuth() {
        if (!this.hasMrtConfig()) {
            throw new Error('MRT auth requires mrtApiKey');
        }
        return new ApiKeyStrategy(this.values.mrtApiKey, 'Authorization');
    }
    createWebDavAuth() {
        // Prefer basic auth if available (simpler, no token refresh)
        if (this.hasBasicAuthConfig()) {
            return this.createBasicAuth();
        }
        // Fall back to OAuth
        if (this.hasOAuthConfig()) {
            return this.createOAuth();
        }
        throw new Error('WebDAV auth requires basic auth (username/password) or OAuth (clientId)');
    }
}
//# sourceMappingURL=resolved-config.js.map