/**
 * @swagger
 * tags:
 *   name: SolaceNet Cards
 *   description: Card issuing and controls
 */

import { Router } from 'express';
import { zeroTrustAuthMiddleware } from '@/integration/api-gateway/middleware/auth.middleware';
import { cardIssuingService, CreateCardRequest, CardControlRequest } from './card-issuing.service';

const router = Router();

router.post('/', zeroTrustAuthMiddleware, async (req, res, next) => {
  try {
    const request = req.body as CreateCardRequest;
    const card = await cardIssuingService.issueCard(request);
    res.status(201).json(card);
  } catch (error) {
    next(error);
  }
});

router.post('/:cardId/control', zeroTrustAuthMiddleware, async (req, res, next) => {
  try {
    const { cardId } = req.params;
    const request = { ...req.body, cardId } as CardControlRequest;
    await cardIssuingService.controlCard(request);
    res.json({ success: true });
  } catch (error) {
    next(error);
  }
});

export default router;
