// SPDX-License-Identifier: Apache-2.0
import { BaseCommandTest } from './base-command-test.js';
import { Flags } from '../../../../src/commands/flags.js';
import { main } from '../../../../src/index.js';
import { Duration } from '../../../../src/core/time/duration.js';
import { InjectTokens } from '../../../../src/core/dependency-injection/inject-tokens.js';
import { expect } from 'chai';
import { container } from 'tsyringe-neo';
import { Templates } from '../../../../src/core/templates.js';
import { RelayCommandDefinition } from '../../../../src/commands/command-definitions/relay-command-definition.js';
export class RelayTest extends BaseCommandTest {
    static NODE_ALIASES_UNPARSED = 'node2';
    static soloRelayDeployArgv(testName, deployment, clusterReference) {
        const { newArgv, argvPushGlobalFlags, optionFromFlag } = RelayTest;
        const argv = newArgv();
        argv.push(RelayCommandDefinition.COMMAND_NAME, RelayCommandDefinition.NODE_SUBCOMMAND_NAME, RelayCommandDefinition.NODE_ADD, optionFromFlag(Flags.deployment), deployment, optionFromFlag(Flags.clusterRef), clusterReference, optionFromFlag(Flags.nodeAliasesUnparsed), RelayTest.NODE_ALIASES_UNPARSED);
        argvPushGlobalFlags(argv, testName, true, false);
        return argv;
    }
    static soloRelayDestroyArgv(testName, deployment, clusterReference) {
        const { newArgv, argvPushGlobalFlags, optionFromFlag } = RelayTest;
        const argv = newArgv();
        argv.push(RelayCommandDefinition.COMMAND_NAME, RelayCommandDefinition.NODE_SUBCOMMAND_NAME, RelayCommandDefinition.NODE_DESTROY, optionFromFlag(Flags.deployment), deployment, optionFromFlag(Flags.clusterRef), clusterReference, optionFromFlag(Flags.nodeAliasesUnparsed), RelayTest.NODE_ALIASES_UNPARSED, optionFromFlag(Flags.quiet), optionFromFlag(Flags.devMode));
        argvPushGlobalFlags(argv, testName, false, true);
        return argv;
    }
    static async verifyRelayDeployWasSuccessful(contexts, namespace) {
        const k8Factory = container.resolve(InjectTokens.K8Factory);
        const relayPods = await k8Factory.getK8(contexts[1]).pods().list(namespace, Templates.renderRelayLabels(1));
        expect(relayPods).to.have.lengthOf(1);
    }
    static add(options) {
        const { testName, deployment, namespace, contexts, clusterReferenceNameArray, testLogger } = options;
        const { soloRelayDeployArgv, verifyRelayDeployWasSuccessful } = RelayTest;
        // TODO: Investigate validations
        it(`${testName}: JSON-RPC relay node add`, async () => {
            await main(soloRelayDeployArgv(testName, deployment, clusterReferenceNameArray[1]));
            await verifyRelayDeployWasSuccessful(contexts, namespace);
        }).timeout(Duration.ofMinutes(5).toMillis());
    }
    static destroy(options) {
        const { testName, deployment, clusterReferenceNameArray } = options;
        const { soloRelayDestroyArgv } = RelayTest;
        it(`${testName}: JSON-RPC relay node destroy`, async () => {
            await main(soloRelayDestroyArgv(testName, deployment, clusterReferenceNameArray[1]));
        }).timeout(Duration.ofMinutes(5).toMillis());
    }
}
//# sourceMappingURL=relay-test.js.map