// src/routes/spotRoutes.js
const express = require("express");
const router = express.Router();
const spotController = require("../controllers/spotController");
const { auth } = require("../middleware/auth");
const { validate, rules, query, param, body } = require("../middleware/validation");

// PUBLIC
router.get("/pairs", [rules.page, rules.limit], validate, spotController.getPairs);
router.get("/tickers", validate, spotController.getTickers);
router.get("/ticker/:symbol", [param("symbol").trim().toUpperCase()], validate, spotController.getTickerBySymbol);
router.get("/orderbook/:symbol", [param("symbol").trim().toUpperCase()], validate, spotController.getOrderBook);
router.get("/trades/:symbol", [param("symbol").trim().toUpperCase()], validate, spotController.getRecentTrades);
router.get("/klines/:symbol", [param("symbol").trim().toUpperCase()], validate, spotController.getKlines);

// PRIVATE
router.get("/balances", auth, spotController.getBalances);
router.get("/orders/open", auth, [rules.page, rules.limit], validate, spotController.getOpenOrders);
router.get("/orders/history", auth, [rules.page, rules.limit], validate, spotController.getOrderHistory);
router.get("/mytrades", auth, [rules.page, rules.limit], validate, spotController.getMyTrades);
router.post("/orders", auth, validate, spotController.placeOrder);
router.delete("/orders/:id", auth, validate, spotController.cancelOrder);
router.delete("/orders", auth, validate, spotController.cancelAllOrders);

module.exports = router;

// src/routes/forexRoutes.js
const express = require("express");
const router = express.Router();
const forexController = require("../controllers/forexController");
const { auth } = require("../middleware/auth");
const { validate, rules, query, param } = require("../middleware/validation");

// PUBLIC
router.get("/pairs", [rules.page, rules.limit], validate, forexController.getPairs);
router.get("/tickers", validate, forexController.getTickers);
router.get("/ticker/:symbol", [param("symbol").trim().toUpperCase()], validate, forexController.getTickerBySymbol);
router.get("/orderbook/:symbol", [param("symbol").trim().toUpperCase()], validate, forexController.getOrderBook);
router.get("/trades/:symbol", [param("symbol").trim().toUpperCase()], validate, forexController.getRecentTrades);
router.get("/klines/:symbol", [param("symbol").trim().toUpperCase()], validate, forexController.getKlines);

// PRIVATE
router.get("/account", auth, forexController.getAccount);
router.get("/positions", auth, [rules.page, rules.limit], validate, forexController.getPositions);
router.post("/positions/:id/close", auth, validate, forexController.closePosition);
router.patch("/positions/:id/tpsl", auth, validate, forexController.updatePositionTpSl);
router.get("/orders/open", auth, [rules.page, rules.limit], validate, forexController.getOpenOrders);
router.get("/orders/history", auth, [rules.page, rules.limit], validate, forexController.getOrderHistory);
router.get("/mytrades", auth, [rules.page, rules.limit], validate, forexController.getMyTrades);
router.post("/orders", auth, validate, forexController.placeOrder);
router.delete("/orders/:id", auth, validate, forexController.cancelOrder);

module.exports = router;

// src/routes/perpsRoutes.js
const express = require("express");
const router = express.Router();
const perpsController = require("../controllers/perpsController");
const { auth } = require("../middleware/auth");
const { validate, rules, param } = require("../middleware/validation");

// PUBLIC
router.get("/pairs", [rules.page, rules.limit], validate, perpsController.getPairs);
router.get("/tickers", validate, perpsController.getTickers);
router.get("/ticker/:symbol", [param("symbol").trim().toUpperCase()], validate, perpsController.getTickerBySymbol);
router.get("/funding/:symbol", [param("symbol").trim().toUpperCase()], validate, perpsController.getFunding);
router.get("/orderbook/:symbol", [param("symbol").trim().toUpperCase()], validate, perpsController.getOrderBook);
router.get("/trades/:symbol", [param("symbol").trim().toUpperCase()], validate, perpsController.getRecentTrades);
router.get("/klines/:symbol", [param("symbol").trim().toUpperCase()], validate, perpsController.getKlines);

// PRIVATE
router.get("/account", auth, perpsController.getAccount);
router.post("/margin-mode", auth, validate, perpsController.setMarginMode);
router.post("/leverage", auth, validate, perpsController.setLeverage);
router.get("/positions", auth, [rules.page, rules.limit], validate, perpsController.getPositions);
router.post("/positions/:id/close", auth, validate, perpsController.closePosition);
router.patch("/positions/:id/tpsl", auth, validate, perpsController.updatePositionTpSl);
router.get("/orders/open", auth, [rules.page, rules.limit], validate, perpsController.getOpenOrders);
router.get("/orders/history", auth, [rules.page, rules.limit], validate, perpsController.getOrderHistory);
router.get("/mytrades", auth, [rules.page, rules.limit], validate, perpsController.getMyTrades);
router.get("/liquidations", auth, [rules.page, rules.limit], validate, perpsController.getLiquidations);
router.post("/orders", auth, validate, perpsController.placeOrder);
router.delete("/orders/:id", auth, validate, perpsController.cancelOrder);

module.exports = router;