// SPDX-License-Identifier: Apache-2.0
import { BaseCommandTest } from './base-command-test.js';
import { main } from '../../../../src/index.js';
import { Flags } from '../../../../src/commands/flags.js';
import { InjectTokens } from '../../../../src/core/dependency-injection/inject-tokens.js';
import { expect } from 'chai';
import { container } from 'tsyringe-neo';
export class DeploymentTest extends BaseCommandTest {
    static soloDeploymentCreateArgv(testName, deployment, namespace, realm, shard) {
        const { newArgv, optionFromFlag, argvPushGlobalFlags } = DeploymentTest;
        const argv = newArgv();
        argv.push('deployment', 'create', optionFromFlag(Flags.deployment), deployment, optionFromFlag(Flags.namespace), namespace.name, optionFromFlag(Flags.realm), String(realm), optionFromFlag(Flags.shard), String(shard));
        argvPushGlobalFlags(argv, testName);
        return argv;
    }
    static create(options) {
        const { testName, testLogger, deployment, namespace, realm, shard } = options;
        const { soloDeploymentCreateArgv } = DeploymentTest;
        it(`${testName}: solo deployment create`, async () => {
            testLogger.info(`${testName}: beginning solo deployment create`);
            await main(soloDeploymentCreateArgv(testName, deployment, namespace, realm, shard));
            // TODO check that the deployment was created
            testLogger.info(`${testName}: finished solo deployment create`);
        });
    }
    static soloDeploymentAddClusterArgv(testName, deployment, clusterReference, numberOfNodes) {
        const { newArgv, optionFromFlag, argvPushGlobalFlags } = DeploymentTest;
        const argv = newArgv();
        argv.push('deployment', 'add-cluster', optionFromFlag(Flags.deployment), deployment, optionFromFlag(Flags.clusterRef), clusterReference, optionFromFlag(Flags.numberOfConsensusNodes), numberOfNodes.toString());
        argvPushGlobalFlags(argv, testName);
        return argv;
    }
    static addCluster(options) {
        const { testName, testLogger, deployment, clusterReferenceNameArray, consensusNodesCount } = options;
        const { soloDeploymentAddClusterArgv } = DeploymentTest;
        it(`${testName}: solo deployment add-cluster`, async () => {
            testLogger.info(`${testName}: beginning solo deployment add-cluster`);
            for (const element of clusterReferenceNameArray) {
                await main(soloDeploymentAddClusterArgv(testName, deployment, element, 1));
            }
            const remoteConfig = container.resolve(InjectTokens.RemoteConfigRuntimeState);
            expect(remoteConfig.isLoaded(), 'remote config manager should be loaded').to.be.true;
            const consensusNodes = remoteConfig.configuration.components.state.consensusNodes;
            expect(Object.entries(consensusNodes).length, `consensus node count should be ${consensusNodesCount}`).to.equal(consensusNodesCount);
            for (const [index, element] of clusterReferenceNameArray.entries()) {
                expect(consensusNodes[index].metadata.cluster).to.equal(element);
            }
            testLogger.info(`${testName}: finished solo deployment add-cluster`);
        });
    }
}
//# sourceMappingURL=deployment-test.js.map