"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildCliproxyAccountKey = exports.parseCliproxyKey = void 0;
const provider_capabilities_1 = require("../../cliproxy/provider-capabilities");
/** Parse CLIProxy account key format: "provider:accountId" */
function parseCliproxyKey(key) {
    let normalizedKey = key;
    if (key.startsWith('cliproxy:')) {
        normalizedKey = key.slice('cliproxy:'.length);
    }
    else if (key.startsWith('cliproxy+')) {
        normalizedKey = key.slice('cliproxy+'.length);
    }
    const colonIndex = normalizedKey.indexOf(':');
    if (colonIndex === -1)
        return null;
    const provider = normalizedKey.slice(0, colonIndex);
    const accountId = normalizedKey.slice(colonIndex + 1);
    if (!(0, provider_capabilities_1.isCLIProxyProvider)(provider) || !accountId)
        return null;
    return { provider, accountId };
}
exports.parseCliproxyKey = parseCliproxyKey;
function buildCliproxyAccountKey(rawKey, merged) {
    const candidateKeys = [rawKey, `cliproxy:${rawKey}`, `cliproxy+${rawKey}`];
    for (const key of candidateKeys) {
        if (!merged[key]) {
            return key;
        }
    }
    return null;
}
exports.buildCliproxyAccountKey = buildCliproxyAccountKey;
//# sourceMappingURL=account-route-helpers.js.map