const express = require('express');

const {
  SERVICE_ENV_KEYS,
  getConfiguredServices,
  isAuthRequired
} = require('../config/serviceCredentials');

const router = express.Router();

router.get('/', (req, res) => {
  res.json({
    ok: true,
    authRequired: isAuthRequired(),
    configuredServices: getConfiguredServices(),
    expectedEnvKeys: SERVICE_ENV_KEYS,
    headers: {
      service: 'X-AISFOR-SERVICE',
      apiKey: 'X-AISFOR-API-KEY',
      signature: 'X-AISFOR-SIGNATURE',
      timestamp: 'X-AISFOR-TIMESTAMP',
      nonce: 'X-AISFOR-NONCE'
    },
    signatureV2: {
      algorithm: 'HMAC-SHA256',
      signedFields: ['serviceName', 'timestamp', 'nonce', 'method', 'path', 'body'],
      maxClockSkewMs: Number(process.env.AISFOR_CHAIN_SIGNATURE_MAX_SKEW_MS || 300000),
      replayProtection: 'per-process nonce cache during mock stage'
    }
  });
});

module.exports = router;

