// SPDX-License-Identifier: Apache-2.0
import { Container } from '../src/core/dependency-injection/container-init.js';
import fs from 'node:fs';
import * as yaml from 'yaml';
import { DEFAULT_LOCAL_CONFIG_FILE } from '../src/core/constants.js';
import { PathEx } from '../src/business/utils/path-ex.js';
import { CommandInvoker } from './helpers/command-invoker.js';
import { InjectTokens } from '../src/core/dependency-injection/inject-tokens.js';
import { SingletonContainer } from '../src/core/dependency-injection/singleton-container.js';
import { ValueContainer } from '../src/core/dependency-injection/value-container.js';
const CACHE_DIRECTORY = PathEx.join('test', 'data', 'tmp');
export function resetTestContainer(cacheDirectory = CACHE_DIRECTORY, containerOverrides = new Map()) {
    // Register test-specific containers
    if (!containerOverrides.get(InjectTokens.CommandInvoker)) {
        containerOverrides.set(InjectTokens.CommandInvoker, new SingletonContainer(InjectTokens.CommandInvoker, CommandInvoker));
    }
    if (!containerOverrides.get(InjectTokens.CommandInvoker)) {
        containerOverrides.set(InjectTokens.CommandInvoker, new SingletonContainer(InjectTokens.CommandInvoker, CommandInvoker));
    }
    if (!containerOverrides.get(InjectTokens.LogLevel)) {
        containerOverrides.set(InjectTokens.LogLevel, new ValueContainer(InjectTokens.LogLevel, 'debug'));
    }
    if (!containerOverrides.get(InjectTokens.DevelopmentMode)) {
        containerOverrides.set(InjectTokens.DevelopmentMode, new ValueContainer(InjectTokens.DevelopmentMode, true));
    }
    // For the test suites cacheDir === homeDir is acceptable because the data is temporary
    Container.getInstance().reset(cacheDirectory, cacheDirectory, 'debug', true, containerOverrides);
}
export function resetForTest(namespace, cacheDirectory = CACHE_DIRECTORY, resetLocalConfig = true, containerOverrides) {
    if (resetLocalConfig) {
        const localConfigFile = DEFAULT_LOCAL_CONFIG_FILE;
        if (!fs.existsSync(CACHE_DIRECTORY)) {
            fs.mkdirSync(CACHE_DIRECTORY, { recursive: true });
        }
        const localConfigData = fs.readFileSync(PathEx.joinWithRealPath('test', 'data', localConfigFile), 'utf8');
        const parsedData = yaml.parse(localConfigData);
        fs.writeFileSync(PathEx.join(CACHE_DIRECTORY, localConfigFile), yaml.stringify(parsedData));
    }
    // need to init the container prior to using K8Client for dependency injection to work
    resetTestContainer(cacheDirectory, containerOverrides);
}
//# sourceMappingURL=test-container.js.map