// GQL API Routes

import { Router } from 'express';
import { gqlBlockEngineService } from './gql-block-engine.service';
import { quantumResistantSignaturesService } from './quantum-resistant-signatures.service';

const router = Router();

router.post('/blocks', async (req, res, next) => {
  try {
    const block = await gqlBlockEngineService.createBlock(
      req.body.blockData,
      req.body.pqSignatures
    );
    res.status(201).json(block);
  } catch (error) {
      return next(error);
  }
});

router.get('/blocks/:blockId', async (req, res, next) => {
  try {
    const block = await gqlBlockEngineService.getBlock(req.params.blockId);
    res.json(block);
  } catch (error) {
      return next(error);
  }
});

router.post('/signatures', async (req, res, next) => {
  try {
    const signature = await quantumResistantSignaturesService.createPQSignatureBlock(
      req.body.blockId,
      req.body.algorithm,
      req.body.signature,
      req.body.publicKey
    );
    res.status(201).json(signature);
  } catch (error) {
      return next(error);
  }
});

export default router;

