import path from "path";
import { SESSION_STORAGE_FILENAME } from "../../types/TestTypes.js";
import { resolveSaveStoragePath } from "./resolveSaveStoragePath.js";
export function resolveSessionPaths(args) {
    const defaultPath = path.join(args.outputDir, SESSION_STORAGE_FILENAME);
    const explicitLoad = args.loadOverride
        ? resolveSaveStoragePath(args.loadOverride, args.outputDir)
        : undefined;
    const explicitSave = args.saveOverride
        ? resolveSaveStoragePath(args.saveOverride, args.outputDir)
        : undefined;
    switch (args.mode) {
        case "capture":
            // Login capture: clean slate (never load), save at default unless overridden.
            return { savePath: explicitSave ?? defaultPath };
        case "reuse":
            // Reuse existing session: load by default, do NOT save (preserves the file).
            // Caller may force a save by setting `playwrightSaveStoragePath` explicitly.
            return {
                loadPath: explicitLoad ?? defaultPath,
                savePath: explicitSave,
            };
        case "ignore":
            // Honor only explicit overrides; otherwise neither load nor save.
            return { loadPath: explicitLoad, savePath: explicitSave };
        case "auto":
        default:
            // Explicit overrides win.
            if (explicitLoad || explicitSave) {
                return { loadPath: explicitLoad, savePath: explicitSave };
            }
            // No overrides — decide from filesystem state. If a session file is
            // already present, reuse it without overwriting; otherwise capture
            // into the default location.
            return args.sessionExists
                ? { loadPath: defaultPath }
                : { savePath: defaultPath };
    }
}
