"use strict";

const router = require("express").Router();
const { authenticateAdmin, audit } = require("../../middleware");
const AdminTradeHistoryController = require("../../controllers/admin/tradeHistoryController");

// Global trades CRUD (admin)
router.get("/trades", authenticateAdmin, AdminTradeHistoryController.listTrades);
router.get("/trades/:tradeId", authenticateAdmin, AdminTradeHistoryController.getTradeById);

router.post(
  "/trades",
  authenticateAdmin,
  audit("trades.create", "trade_history"),
  AdminTradeHistoryController.createTrade
);

router.patch(
  "/trades/:tradeId",
  authenticateAdmin,
  audit("trades.update", "trade_history"),
  AdminTradeHistoryController.updateTrade
);

router.delete(
  "/trades/:tradeId",
  authenticateAdmin,
  audit("trades.delete", "trade_history"),
  AdminTradeHistoryController.deleteTrade
);

// Close trade (won/loss/refund) + update user balance + create transaction
router.post(
  "/trades/:tradeId/close",
  authenticateAdmin,
  audit("trades.close", "trade_history"),
  AdminTradeHistoryController.closeTrade
);

module.exports = router;

