import * as fs from "fs/promises";
import { getConfigPath, updateConfig, } from "../../cli/config.js";
export const saveTestingConfig = async (args) => {
    await fs.rm(getConfigPath(), { force: true });
    const auth = buildAuthForTest(args);
    await updateConfig({
        ...(auth != null ? { auth } : {}),
        ...(args.sendSessionTranscript != null
            ? { sendSessionTranscript: args.sendSessionTranscript }
            : {}),
        ...(args.autoupdate != null ? { autoupdate: args.autoupdate } : {}),
        ...(args.activeSkillset != null
            ? { activeSkillset: args.activeSkillset }
            : {}),
        ...(args.defaultAgents != null
            ? { defaultAgents: args.defaultAgents }
            : {}),
        ...(args.transcriptDestination != null
            ? { transcriptDestination: args.transcriptDestination }
            : {}),
        ...(args.garbageCollectTranscripts != null
            ? { garbageCollectTranscripts: args.garbageCollectTranscripts }
            : {}),
        ...(args.redownloadOnSwitch != null
            ? { redownloadOnSwitch: args.redownloadOnSwitch }
            : {}),
        ...(args.claudeCodeStatusLine != null
            ? { claudeCodeStatusLine: args.claudeCodeStatusLine }
            : {}),
        installDir: args.installDir,
    });
};
const buildAuthForTest = (args) => {
    const hasUsernameAuth = args.username != null && args.organizationUrl != null;
    const hasIdTokenAuth = args.idToken != null && args.organizationUrl != null;
    const hasApiTokenAuth = args.apiToken != null && args.organizationUrl != null;
    if (!hasUsernameAuth && !hasIdTokenAuth && !hasApiTokenAuth) {
        return undefined;
    }
    return {
        username: args.username,
        organizationUrl: args.organizationUrl,
        refreshToken: args.refreshToken ?? null,
        idToken: args.idToken ?? null,
        idTokenExpiresAt: args.idTokenExpiresAt ?? null,
        password: args.refreshToken != null ? null : (args.password ?? null),
        apiToken: args.apiToken ?? null,
        organizations: args.organizations ?? null,
        isAdmin: args.isAdmin ?? null,
    };
};
//# sourceMappingURL=config.js.map