import { SPECIAL_USERS } from './default-config';
/**
 * Utility class to build a configuration
 */
var TapConfiguratorConfigBuilder = /** @class */ (function () {
    function TapConfiguratorConfigBuilder(_schema) {
        this._schema = _schema;
    }
    Object.defineProperty(TapConfiguratorConfigBuilder.prototype, "configData", {
        get: function () {
            if (!this._schema.config.data) {
                this._schema.config.data = {};
            }
            return this._schema.config.data;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapConfiguratorConfigBuilder.prototype, "profiles", {
        get: function () {
            if (!this.configData.profiles) {
                this.configData.profiles = [];
            }
            return this.configData.profiles;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapConfiguratorConfigBuilder.prototype, "tapConfig", {
        get: function () {
            if (!this._schema.config.tap) {
                this._schema.config.tap = {};
            }
            return this._schema.config.tap;
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @deprecated
     * TODO move from here as factory method should not polute the class
     */
    TapConfiguratorConfigBuilder.default = function () {
        return new TapConfiguratorConfigBuilder({
            meta: {},
            config: {
                application: {
                    name: "TAP"
                },
                version: "1.0.0",
                tap: {
                    security: {
                        disableHardwareFactoryReset: false,
                        hashPassword: true,
                        disableLoginWithUID: false,
                        disableResourceFactoryReset: false,
                        scramActivated: false
                    },
                    scram: {
                        hashIteration: 5000
                    }
                },
                data: {
                    profiles: SPECIAL_USERS
                }
            }
        });
    };
    /**
     * Set application name
     * @param appName
     */
    TapConfiguratorConfigBuilder.prototype.appName = function (appName) {
        if (!this._schema.config.application) {
            this._schema.config.application = {};
        }
        this._schema.config.application.name = appName;
        return this;
    };
    /**
     * Edit user identified by username
     * If user does not it will be created with default values
     * @param username
     * @param editor
     */
    TapConfiguratorConfigBuilder.prototype.user = function (username, editor) {
        var userDataIndex = this.profiles.findIndex(function (p) { return p.username === username; });
        var userData = userDataIndex >= 0 ? this.profiles[userDataIndex] : undefined;
        if (!userData) {
            // TODO check SpecialProfileConfig
            userData = {
                username: username,
                lifeTime: 300,
                password: username,
            };
        }
        userData = editor(userData);
        this.profiles[userDataIndex] = userData;
        return this;
    };
    /**
     * Enable/disable scram
     * @param enabled true to enable scram
     */
    TapConfiguratorConfigBuilder.prototype.scram = function (enabled) {
        // TODO hash iteration count ? 
        if (!this.tapConfig.security) {
            this.tapConfig.security = {
                scramActivated: false,
                disableHardwareFactoryReset: false,
                hashPassword: true,
                disableResourceFactoryReset: false,
                disableLoginWithUID: false
            };
        }
        else {
            this.tapConfig.security.scramActivated = enabled;
            if (enabled) {
                this.tapConfig.security.hashPassword = true;
            }
        }
        return this;
    };
    TapConfiguratorConfigBuilder.prototype.build = function () {
        return this._schema;
    };
    return TapConfiguratorConfigBuilder;
}());
export { TapConfiguratorConfigBuilder };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFwLWNvbmZpZy1zY2hlbWEtYnVpbGRlci5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0Bpb3RpemUvdGFwL2NvbmZpZ3VyYXRvci8iLCJzb3VyY2VzIjpbImxpYi90YXAtY29uZmlnLXNjaGVtYS1idWlsZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUlqRDs7R0FFRztBQUNIO0lBRUksc0NBQW9CLE9BQThCO1FBQTlCLFlBQU8sR0FBUCxPQUFPLENBQXVCO0lBRWxELENBQUM7SUFFRCxzQkFBWSxvREFBVTthQUF0QjtZQUNJLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxJQUFJLEVBQUU7Z0JBQzNCLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLElBQUksR0FBRyxFQUFFLENBQUM7YUFDakM7WUFDRCxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQztRQUNwQyxDQUFDOzs7T0FBQTtJQUVELHNCQUFZLGtE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