// POST /api/admin/parse {key} [auth: x-admin-password] → decompõe a key
const { parseKeyPublic, requireAdmin, readBody, json, listBlacklist } = require('../_lib');

module.exports = async (req, res) => {
  if (req.method === 'OPTIONS') return json(res, 204, {});
  if (req.method !== 'POST') return json(res, 405, { ok: false, reason: 'use POST' });
  if (!requireAdmin(req)) return json(res, 401, { ok: false, reason: 'unauthorized' });
  const body = await readBody(req);
  const p = parseKeyPublic(body.key || '');
  if (!p) return json(res, 400, { ok: false, reason: 'key inválida' });
  const revoked = listBlacklist().includes((body.key || '').trim());
  return json(res, 200, { ok: true, ...p, revoked });
};
