const express = require('express');
const testnetService = require('../services/testnetService');

const router = express.Router();

router.get('/status', async (req, res, next) => {
  try {
    res.json({ ok: true, testnet: await testnetService.refreshStatus() });
  } catch (error) {
    next(error);
  }
});

router.get('/genesis', async (req, res, next) => {
  try {
    await testnetService.refreshStatus();
    res.json({ ok: true, genesis: testnetService.getGenesisPreview() });
  } catch (error) {
    next(error);
  }
});

router.get('/validators', async (req, res, next) => {
  try {
    await testnetService.refreshStatus();
    res.json({ ok: true, ledgerRole: 'canonical-candidate-ledger', validators: testnetService.getValidators() });
  } catch (error) {
    next(error);
  }
});

module.exports = router;
