// SPDX-License-Identifier: Apache-2.0
import { MutableFacadeArray } from '../../collection/mutable-facade-array.js';
import { Deployment } from './deployment.js';
import { DeploymentSchema } from '../../../../data/schema/model/local/deployment-schema.js';
import { UserIdentity } from '../common/user-identity.js';
import { UserIdentitySchema } from '../../../../data/schema/model/common/user-identity-schema.js';
import { MutableFacadeMap } from '../../collection/mutable-facade-map.js';
import { StringFacade } from '../../facade/string-facade.js';
import { DeploymentNotFoundError } from '../../../errors/deployment-not-found-error.js';
import { ApplicationVersions } from '../common/application-versions.js';
import { ApplicationVersionsSchema } from '../../../../data/schema/model/common/application-versions-schema.js';
export class LocalConfig {
    encapsulatedObject;
    _clusterRefs;
    _deployments;
    _userIdentity;
    _versions;
    constructor(encapsulatedObject) {
        this.encapsulatedObject = encapsulatedObject;
        // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
        this._clusterRefs = new MutableFacadeMap(StringFacade, String, encapsulatedObject.clusterRefs ?? new Map());
        this._deployments = new MutableFacadeArray(Deployment, DeploymentSchema, encapsulatedObject.deployments ?? []);
        this._userIdentity = new UserIdentity(encapsulatedObject.userIdentity ?? new UserIdentitySchema());
        this._versions = new ApplicationVersions(encapsulatedObject.versions ?? new ApplicationVersionsSchema());
    }
    get deployments() {
        return this._deployments;
    }
    get userIdentity() {
        return this._userIdentity;
    }
    get clusterRefs() {
        return this._clusterRefs;
    }
    get versions() {
        return this._versions;
    }
    deploymentByName(deploymentName) {
        const deployment = this.deployments.find((d) => d.name === deploymentName);
        if (!deployment) {
            throw new DeploymentNotFoundError(`Deployment ${deploymentName} not found in local config`);
        }
        return deployment;
    }
    realmForDeployment(deploymentName) {
        return this.deploymentByName(deploymentName).realm;
    }
    shardForDeployment(deploymentName) {
        return this.deploymentByName(deploymentName).shard;
    }
}
//# sourceMappingURL=local-config.js.map