"use strict";
/**
 * Generate a JWT token for the Long Tail dashboard.
 *
 * Usage:
 *   npx ts-node scripts/token.ts
 *   npx ts-node scripts/token.ts --userId admin --role superadmin
 *   npx ts-node scripts/token.ts --userId reviewer1 --roles reviewer,compliance
 *
 * Or via npm script:
 *   npm run token
 *   npm run token -- --userId admin --role superadmin
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
const args = process.argv.slice(2);
function getArg(name, fallback) {
    const idx = args.indexOf(`--${name}`);
    return idx !== -1 && args[idx + 1] ? args[idx + 1] : fallback;
}
const userId = getArg('userId', 'admin');
const role = getArg('role', 'superadmin');
const rolesArg = getArg('roles', '');
const secret = process.env.JWT_SECRET || 'lt-dev-secret';
const expiresIn = getArg('expires', '7d');
// Build roles array for the dashboard auth context
const roleNames = rolesArg ? rolesArg.split(',') : [role];
const roles = roleNames.map((r) => ({
    role: r.trim(),
    type: r.trim() === 'superadmin' ? 'superadmin' : 'member',
}));
const payload = { userId, role, roles };
const token = jsonwebtoken_1.default.sign(payload, secret, { expiresIn });
console.log('\n  HotMesh Long Tail — Token Generator\n');
console.log('  Payload:', JSON.stringify(payload, null, 2));
console.log('  Expires:', expiresIn);
console.log('  Secret:', secret === 'lt-dev-secret' ? 'lt-dev-secret (default)' : '***');
console.log('\n  Token:\n');
console.log(`  ${token}\n`);
