"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("@deepstream/types");
/**
 * The open authentication handler allows every client to connect.
 * If the client specifies a username as part of its authentication
 * data, it will be used to identify the user internally
 */
class CombineAuthentication extends types_1.DeepstreamPlugin {
    constructor(auths) {
        super();
        this.auths = auths;
        this.description = '';
        if (auths.length === 1) {
            this.description = auths[0].description;
        }
        else {
            this.description = auths.map((auth, index) => `\n\t${index}) ${auth.description}`).join('');
        }
    }
    async whenReady() {
        await Promise.all(this.auths.map((auth) => auth.whenReady()));
    }
    async close() {
        await Promise.all(this.auths.map((auth) => auth.close()));
    }
    async isValidUser(connectionData, authData, callback) {
        for (const auth of this.auths) {
            const result = await auth.isValidUser(connectionData, authData);
            if (result) {
                callback(result.isValid, result);
                return;
            }
        }
        callback(false);
    }
    onClientDisconnect(userId) {
        for (const auth of this.auths) {
            if (auth.onClientDisconnect) {
                auth.onClientDisconnect(userId);
            }
        }
    }
}
exports.CombineAuthentication = CombineAuthentication;
//# sourceMappingURL=combine-authentication.js.map