// SPDX-License-Identifier: Apache-2.0
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var LayeredConfigProvider_1;
import { LayeredConfigBuilder } from './layered-config-builder.js';
import { InjectTokens } from '../../../core/dependency-injection/inject-tokens.js';
import { inject, injectable } from 'tsyringe-neo';
import { patchInject } from '../../../core/dependency-injection/container-helper.js';
import { IllegalArgumentError } from '../../../business/errors/illegal-argument-error.js';
import { ConfigurationError } from '../api/configuration-error.js';
let LayeredConfigProvider = LayeredConfigProvider_1 = class LayeredConfigProvider {
    mapper;
    prefix;
    _config;
    constructor(mapper, prefix = 'SOLO') {
        this.mapper = mapper;
        this.prefix = prefix;
        this.mapper = patchInject(mapper, InjectTokens.ObjectMapper, LayeredConfigProvider_1.name);
    }
    builder() {
        return new LayeredConfigBuilder(this, this.mapper, this.prefix);
    }
    config() {
        if (!this._config) {
            throw new ConfigurationError('config not registered');
        }
        return this._config;
    }
    register(config) {
        if (!config) {
            throw new IllegalArgumentError('config must not be null or undefined');
        }
        if (this._config) {
            throw new ConfigurationError('config already registered');
        }
        this._config = config;
    }
    release() {
        this._config = undefined;
    }
};
LayeredConfigProvider = LayeredConfigProvider_1 = __decorate([
    injectable(),
    __param(0, inject(InjectTokens.ObjectMapper)),
    __metadata("design:paramtypes", [Object, String])
], LayeredConfigProvider);
export { LayeredConfigProvider };
//# sourceMappingURL=layered-config-provider.js.map