"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LogStoreClientConfigInjectionToken = exports.validateConfig = exports.createStrictConfig = void 0;
const ajv_1 = __importDefault(require("ajv"));
const ajv_formats_1 = __importDefault(require("ajv-formats"));
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
const config_schema_json_1 = __importDefault(require("./config.schema.json"));
const utils_1 = require("./utils/utils");
const createStrictConfig = (input = {}) => {
    const config = (0, exports.validateConfig)((0, cloneDeep_1.default)(input));
    config.id ??= (0, utils_1.generateClientId)();
    return config;
};
exports.createStrictConfig = createStrictConfig;
const validateConfig = (data) => {
    const ajv = new ajv_1.default({
        useDefaults: true,
    });
    (0, ajv_formats_1.default)(ajv);
    ajv.addFormat('ethereum-address', /^0x[a-zA-Z0-9]{40}$/);
    ajv.addFormat('ethereum-private-key', /^(0x)?[a-zA-Z0-9]{64}$/);
    const validate = ajv.compile(config_schema_json_1.default);
    if (!validate(data)) {
        throw new Error(validate
            .errors.map((e) => {
            let text = ajv.errorsText([e], { dataVar: '' }).trim();
            if (e.params.additionalProperty) {
                text += `: ${e.params.additionalProperty}`;
            }
            return text;
        })
            .join('\n'));
    }
    return data;
};
exports.validateConfig = validateConfig;
exports.LogStoreClientConfigInjectionToken = Symbol('LogStoreClientConfig');
//# sourceMappingURL=Config.js.map