// SPDX-License-Identifier: Apache-2.0
import { BaseCommandTest } from './base-command-test.js';
import { main } from '../../../../src/index.js';
import { InjectTokens } from '../../../../src/core/dependency-injection/inject-tokens.js';
import { Flags } from '../../../../src/commands/flags.js';
import { container } from 'tsyringe-neo';
import { expect } from 'chai';
import { ClusterReferenceCommandDefinition } from '../../../../src/commands/command-definitions/cluster-reference-command-definition.js';
export class ClusterReferenceTest extends BaseCommandTest {
    static soloClusterReferenceConnectArgv(testName, clusterReference, context) {
        const { newArgv, optionFromFlag, argvPushGlobalFlags } = ClusterReferenceTest;
        const argv = newArgv();
        argv.push(ClusterReferenceCommandDefinition.COMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_SUBCOMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_CONNECT, optionFromFlag(Flags.clusterRef), clusterReference, optionFromFlag(Flags.context), context);
        argvPushGlobalFlags(argv, testName);
        return argv;
    }
    static connect(options) {
        const { testName, testLogger, clusterReferences, clusterReferenceNameArray, contexts } = options;
        const { soloClusterReferenceConnectArgv } = ClusterReferenceTest;
        it(`${testName}: solo cluster-ref config connect`, async () => {
            testLogger.info(`${testName}: beginning solo cluster-ref config connect`);
            for (const [clusterReferenceName, context] of clusterReferences.entries()) {
                await main(soloClusterReferenceConnectArgv(testName, clusterReferenceName, context));
            }
            const localConfig = container.resolve(InjectTokens.LocalConfigRuntimeState);
            const clusterReferencesActual = localConfig.configuration.clusterRefs;
            expect(clusterReferencesActual.get(clusterReferenceNameArray[0])?.toString()).to.equal(contexts[0]);
            expect(clusterReferencesActual.get(clusterReferenceNameArray[1])?.toString()).to.equal(contexts[1]);
            testLogger.info(`${testName}: finished solo cluster-ref config connect`);
        });
    }
    static soloClusterReferenceSetup(testName, clusterReference, clusterSetupNamespace) {
        const { newArgv, optionFromFlag, argvPushGlobalFlags } = ClusterReferenceTest;
        const argv = newArgv();
        argv.push(ClusterReferenceCommandDefinition.COMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_SUBCOMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_SETUP, optionFromFlag(Flags.clusterRef), clusterReference);
        if (clusterSetupNamespace) {
            argv.push(optionFromFlag(Flags.clusterSetupNamespace), clusterSetupNamespace);
        }
        argvPushGlobalFlags(argv, testName, false, true);
        return argv;
    }
    static setup(options) {
        const { testName, testLogger, clusterReferenceNameArray } = options;
        const { soloClusterReferenceSetup } = ClusterReferenceTest;
        it(`${testName}: solo cluster-ref config setup`, async () => {
            testLogger.info(`${testName}: beginning solo cluster-ref config setup`);
            for (const clusterReferenceName of clusterReferenceNameArray) {
                await main(soloClusterReferenceSetup(testName, clusterReferenceName));
            }
            // TODO add some verification that the setup was successful
            testLogger.info(`${testName}: finishing solo cluster-ref config setup`);
        });
    }
    static soloClusterReferenceReset(testName, clusterReference, clusterSetupNamespace) {
        const { newArgv, optionFromFlag, argvPushGlobalFlags } = ClusterReferenceTest;
        const argv = newArgv();
        argv.push(ClusterReferenceCommandDefinition.COMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_SUBCOMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_RESET, optionFromFlag(Flags.clusterRef), clusterReference, optionFromFlag(Flags.force), optionFromFlag(Flags.quiet));
        if (clusterSetupNamespace) {
            argv.push(optionFromFlag(Flags.clusterSetupNamespace), clusterSetupNamespace);
        }
        argvPushGlobalFlags(argv, testName, false, true);
        return argv;
    }
    static reset(options) {
        const { testName, testLogger, clusterReferenceNameArray } = options;
        const { soloClusterReferenceReset } = ClusterReferenceTest;
        it(`${testName}: solo cluster-ref config reset`, async () => {
            testLogger.info(`${testName}: beginning solo cluster-ref config reset`);
            for (const clusterReferenceName of clusterReferenceNameArray) {
                await main(soloClusterReferenceReset(testName, clusterReferenceName));
            }
            testLogger.info(`${testName}: finishing solo cluster-ref config reset`);
        });
    }
    static soloClusterReferenceInfo(testName, clusterReference) {
        const { newArgv, optionFromFlag, argvPushGlobalFlags } = ClusterReferenceTest;
        const argv = newArgv();
        argv.push(ClusterReferenceCommandDefinition.COMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_SUBCOMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_INFO, optionFromFlag(Flags.clusterRef), clusterReference, optionFromFlag(Flags.quiet));
        argvPushGlobalFlags(argv, testName);
        return argv;
    }
    static info(options) {
        const { testName, testLogger, clusterReferenceNameArray } = options;
        const { soloClusterReferenceInfo } = ClusterReferenceTest;
        it(`${testName}: solo cluster-ref config info`, async () => {
            testLogger.info(`${testName}: beginning solo cluster-ref config info`);
            for (const clusterReferenceName of clusterReferenceNameArray) {
                await main(soloClusterReferenceInfo(testName, clusterReferenceName));
            }
            testLogger.info(`${testName}: finishing solo cluster-ref config info`);
        });
    }
    static soloClusterReferenceList(testName) {
        const { newArgv, optionFromFlag, argvPushGlobalFlags } = ClusterReferenceTest;
        const argv = newArgv();
        argv.push(ClusterReferenceCommandDefinition.COMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_SUBCOMMAND_NAME, ClusterReferenceCommandDefinition.CONFIG_INFO, optionFromFlag(Flags.quiet));
        argvPushGlobalFlags(argv, testName);
        return argv;
    }
    static list(options) {
        const { testName, testLogger } = options;
        const { soloClusterReferenceList } = ClusterReferenceTest;
        it(`${testName}: solo cluster-ref config list`, async () => {
            testLogger.info(`${testName}: beginning solo cluster-ref config list`);
            await main(soloClusterReferenceList(testName));
            testLogger.info(`${testName}: finishing solo cluster-ref config list`);
        });
    }
}
//# sourceMappingURL=cluster-reference-test.js.map