"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.decodeAccountIdentity = void 0;
const fs = __importStar(require("fs"));
const logging_1 = require("../services/logging");
const decode_id_token_1 = require("./decode-id-token");
const logger = (0, logging_1.createLogger)('codex-auth:identity');
/**
 * Read auth.json from disk and extract display-safe identity fields.
 * Returns {} on any error (missing file, bad JSON, missing token, decode failure).
 * Never throws.
 */
function decodeAccountIdentity(authJsonPath) {
    try {
        const raw = fs.readFileSync(authJsonPath, 'utf8');
        const parsed = JSON.parse(raw);
        const idToken = parsed?.tokens?.id_token;
        if (typeof idToken !== 'string' || idToken.length === 0) {
            return {};
        }
        return (0, decode_id_token_1.decodeIdToken)(idToken);
    }
    catch (err) {
        const msg = err instanceof Error ? err.message : String(err);
        logger.warn('codex-auth.identity.decode-failed', `Failed to decode account identity from ${authJsonPath}: ${msg}`);
        return {};
    }
}
exports.decodeAccountIdentity = decodeAccountIdentity;
//# sourceMappingURL=codex-account-identity.js.map