// GLP API Routes

import { Router } from 'express';
import { glpService } from './glp-service';
import { liquidityScoreService } from './liquidity-score.service';
import { glpWithdrawalService } from './glp-withdrawal.service';

const router = Router();

/**
 * @swagger
 * /api/v1/glp/contribute:
 *   post:
 *     summary: Contribute to GLP
 */
router.post('/contribute', async (req, res, next) => {
  try {
    const contributionId = await glpService.contribute(req.body);
    res.json({ contributionId });
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/glp/withdraw:
 *   post:
 *     summary: Request withdrawal (Tier 1/2/3)
 */
router.post('/withdraw', async (req, res, next) => {
  try {
    const withdrawalId = await glpService.requestWithdrawal(req.body);
    res.json({ withdrawalId });
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/glp/balance:
 *   get:
 *     summary: Get GLP balance
 */
router.get('/balance', async (req, res, next) => {
  try {
    const { currencyCode } = req.query;
    const balance = await glpService.getBalance(currencyCode as string);
    res.json(balance);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/glp/liquidity-score/:bankId:
 *   get:
 *     summary: Get liquidity score
 */
router.get('/liquidity-score/:bankId', async (req, res, next) => {
  try {
    const score = await liquidityScoreService.getLiquidityScore(req.params.bankId);
    res.json(score);
  } catch (error) {
      return next(error);
  }
});

/**
 * @swagger
 * /api/v1/glp/withdrawals/pending:
 *   get:
 *     summary: List pending withdrawals
 */
router.get('/withdrawals/pending', async (req, res, next) => {
  try {
    const { withdrawalTier, limit } = req.query;
    const withdrawals = await glpWithdrawalService.getPendingWithdrawals(
      withdrawalTier as string,
      parseInt(limit as string) || 100
    );
    res.json(withdrawals);
  } catch (error) {
      return next(error);
  }
});

export default router;

