// 健康检查

const express = require('express');
const { listProfiles } = require('../lib/profile-store');

const router = express.Router();

router.get('/health', (req, res) => {
  let profileCount = 0;
  let storageOk = true;
  try {
    profileCount = listProfiles().length;
  } catch {
    // P3 修复：区分"无 profile"和"读取失败"
    storageOk = false;
  }

  // P2 修复：不泄露 syncSecretConfigured 等安全配置状态
  res.json({
    status: storageOk ? 'ok' : 'degraded',
    service: 'hermes-server',
    timestamp: new Date().toISOString(),
    profileCount,
  });
});

module.exports = router;
