"use strict";
/**
 * Path resolution utilities for CLIProxy directories and files
 * Centralizes all path management for CLIProxy configuration
 */
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.migrateLegacyProviderSettingsIfNeeded = exports.getLegacyProviderSettingsPath = exports.getDedicatedProviderSettingsPath = exports.getProviderSettingsPath = exports.getBinDir = exports.getCliproxyConfigPath = exports.getConfigPathForPort = exports.getProviderAuthDir = exports.getAuthDir = exports.getCliproxyWritablePath = exports.getCliproxyProvidersDir = exports.getCliproxyDir = void 0;
const path = __importStar(require("path"));
const port_manager_1 = require("./port-manager");
const config_loader_facade_1 = require("../../config/config-loader-facade");
/**
 * Get CLIProxy base directory
 * All CLIProxy-related files are stored under ~/.ccs/cliproxy/
 */
function getCliproxyDir() {
    return path.join((0, config_loader_facade_1.getCcsDir)(), 'cliproxy');
}
exports.getCliproxyDir = getCliproxyDir;
/**
 * Get CLIProxy provider settings directory.
 */
function getCliproxyProvidersDir() {
    return path.join(getCliproxyDir(), 'providers');
}
exports.getCliproxyProvidersDir = getCliproxyProvidersDir;
/**
 * Get CLIProxy writable directory for logs and runtime files.
 * This directory is set as WRITABLE_PATH env var when spawning CLIProxy.
 * Logs will be stored in ~/.ccs/cliproxy/logs/
 */
function getCliproxyWritablePath() {
    return path.join((0, config_loader_facade_1.getCcsDir)(), 'cliproxy');
}
exports.getCliproxyWritablePath = getCliproxyWritablePath;
/**
 * Get base auth directory for CLIProxyAPI
 */
function getAuthDir() {
    return path.join(getCliproxyDir(), 'auth');
}
exports.getAuthDir = getAuthDir;
/**
 * Get auth directory for provider
 * All providers use a FLAT auth directory structure for unified config.
 * CLIProxyAPI stores OAuth tokens directly in auth/ (not subdirectories).
 * This enables all providers to be discovered and used concurrently.
 */
function getProviderAuthDir(_provider) {
    // Use flat structure - all auth files in same directory for unified discovery
    // Provider param kept for API compatibility (CLIProxyAPI handles via auth file type field)
    return path.join(getCliproxyDir(), 'auth');
}
exports.getProviderAuthDir = getProviderAuthDir;
/**
 * Get config file path for a specific port.
 * Default port uses config.yaml, others use config-{port}.yaml.
 */
function getConfigPathForPort(port) {
    if (port === port_manager_1.CLIPROXY_DEFAULT_PORT) {
        return path.join(getCliproxyDir(), 'config.yaml');
    }
    return path.join(getCliproxyDir(), `config-${port}.yaml`);
}
exports.getConfigPathForPort = getConfigPathForPort;
/**
 * Get CLIProxy config file path (default port)
 * Named distinctly from config-manager's getConfigPath to avoid confusion.
 */
function getCliproxyConfigPath() {
    return getConfigPathForPort(port_manager_1.CLIPROXY_DEFAULT_PORT);
}
exports.getCliproxyConfigPath = getCliproxyConfigPath;
/**
 * Get binary directory path
 */
function getBinDir() {
    return path.join(getCliproxyDir(), 'bin');
}
exports.getBinDir = getBinDir;
/**
 * Get path to user settings file for provider
 * Example: ~/.ccs/gemini.settings.json
 */
function getProviderSettingsPath(provider) {
    if (provider === 'cursor') {
        return path.join(getCliproxyProvidersDir(), `${provider}.settings.json`);
    }
    return getLegacyProviderSettingsPath(provider);
}
exports.getProviderSettingsPath = getProviderSettingsPath;
/**
 * Get CLIProxy provider settings path in the dedicated cliproxy/providers namespace.
 * Used only for providers that must not collide with legacy top-level settings files.
 */
function getDedicatedProviderSettingsPath(provider) {
    return path.join(getCliproxyProvidersDir(), `${provider}.settings.json`);
}
exports.getDedicatedProviderSettingsPath = getDedicatedProviderSettingsPath;
/**
 * Get legacy provider settings file path in ~/.ccs root.
 * This is kept for compatibility reads/migration of older provider settings.
 */
function getLegacyProviderSettingsPath(provider) {
    return path.join((0, config_loader_facade_1.getCcsDir)(), `${provider}.settings.json`);
}
exports.getLegacyProviderSettingsPath = getLegacyProviderSettingsPath;
/**
 * Resolve the effective provider settings path.
 *
 * Cursor uses a dedicated cliproxy/providers namespace so it does not collide
 * with the deprecated Cursor IDE bridge raw settings file.
 */
function migrateLegacyProviderSettingsIfNeeded(provider) {
    if (provider !== 'cursor') {
        return getProviderSettingsPath(provider);
    }
    const targetPath = getDedicatedProviderSettingsPath(provider);
    return targetPath;
}
exports.migrateLegacyProviderSettingsIfNeeded = migrateLegacyProviderSettingsIfNeeded;
//# sourceMappingURL=path-resolver.js.map