"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSharedCodexConfigPath = exports.resolveCodexProfileDir = exports.getCodexInstancesDir = exports.getCodexAuthRegistryPath = void 0;
const path = __importStar(require("path"));
const os = __importStar(require("os"));
const config_manager_1 = require("../utils/config-manager");
const types_1 = require("./types");
function getCodexAuthRegistryPath() {
    return path.join((0, config_manager_1.getCcsDir)(), 'codex-profiles.yaml');
}
exports.getCodexAuthRegistryPath = getCodexAuthRegistryPath;
function getCodexInstancesDir() {
    return path.join((0, config_manager_1.getCcsDir)(), 'codex-instances');
}
exports.getCodexInstancesDir = getCodexInstancesDir;
function resolveCodexProfileDir(name) {
    const nameError = (0, types_1.getCodexProfileNameError)(name);
    if (nameError) {
        throw new Error(nameError);
    }
    const instancesDir = path.resolve(getCodexInstancesDir());
    const profileDir = path.resolve(path.join(instancesDir, name));
    if (profileDir !== instancesDir && profileDir.startsWith(`${instancesDir}${path.sep}`)) {
        return profileDir;
    }
    throw new Error('Profile directory resolved outside codex-instances.');
}
exports.resolveCodexProfileDir = resolveCodexProfileDir;
// Uses os.homedir() intentionally — this is the upstream Codex location,
// not a CCS-owned path. Tests must override the shared config path explicitly.
function getSharedCodexConfigPath() {
    return path.join(os.homedir(), '.codex', 'config.toml');
}
exports.getSharedCodexConfigPath = getSharedCodexConfigPath;
//# sourceMappingURL=codex-profile-paths.js.map