"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyCredential = void 0;
class LazyCredential {
    instanceUrl;
    authResolver;
    resolveAuthPromise;
    constructor(instanceUrl, authResolver) {
        this.instanceUrl = instanceUrl;
        this.authResolver = authResolver;
    }
    getUrl() {
        return this.instanceUrl;
    }
    resolveAuth() {
        this.resolveAuthPromise ??= Promise.resolve(this.authResolver());
        return this.resolveAuthPromise;
    }
    async getSysParmCk() {
        const auth = await this.resolveAuth();
        return auth.type === 'basic' ? (auth.token ?? '') : '';
    }
    async getHeaders() {
        const resolvedAuth = await this.resolveAuth();
        const headers = {};
        switch (resolvedAuth.type) {
            case 'basic':
                if (resolvedAuth.token) {
                    headers['X-UserToken'] = resolvedAuth.token;
                }
                if (resolvedAuth.cookie) {
                    headers['Cookie'] = resolvedAuth.cookie;
                }
                break;
            case 'oauth':
                headers['Authorization'] = `Bearer ${resolvedAuth.token}`;
                break;
            case 'kaa_jwt':
                headers['X-Kaa-JWT'] = resolvedAuth.token;
                break;
        }
        return headers;
    }
}
exports.LazyCredential = LazyCredential;
//# sourceMappingURL=credentials.js.map