const express = require("express");
const router = express.Router();

const spotController = require("../controllers/spotController");
const { optionalAuth, auth } = require("../middleware/auth");
const { validate, rules, query, param, body } = require("../middleware/validation");

/**
 * Public Market Data (Spot)
 */
router.get(
  "/pairs",
  [
    query("base").optional().trim().toUpperCase(),
    query("quote").optional().trim().toUpperCase(),
    query("status").optional().isIn(["active", "inactive", "halted"]),
    rules.page,
    rules.limit,
  ],
  validate,
  spotController.getPairs
);
/* 
router.get(
  "/ticker",
  [query("symbol").optional().trim().toUpperCase()],
  validate,
  spotController.getTickers
);

router.get(
  "/ticker/:symbol",
  [param("symbol").trim().toUpperCase()],
  validate,
  spotController.getTickerBySymbol
);

router.get(
  "/orderbook/:symbol",
  [
    param("symbol").trim().toUpperCase(),
    query("limit").optional().isInt({ min: 1, max: 1000 }).toInt(),
  ],
  validate,
  spotController.getOrderBook
);

router.get(
  "/trades/:symbol",
  [
    param("symbol").trim().toUpperCase(),
    query("limit").optional().isInt({ min: 1, max: 1000 }).toInt(),
  ],
  validate,
  spotController.getRecentTrades
);

router.get(
  "/klines/:symbol",
  [
    param("symbol").trim().toUpperCase(),
    query("interval").optional().isIn(["1m","5m","15m","1h","4h","1d","1w"]),
    query("limit").optional().isInt({ min: 1, max: 2000 }).toInt(),
  ],
  validate,
  spotController.getKlines
); */

/**
 * Private Trading (Spot)
 */
/* router.get("/balances", auth, spotController.getBalances);

router.get(
  "/orders/open",
  auth,
  [
    query("symbol").optional().trim().toUpperCase(),
    rules.page,
    rules.limit,
  ],
  validate,
  spotController.getOpenOrders
);

router.get(
  "/orders/history",
  auth,
  [
    query("symbol").optional().trim().toUpperCase(),
    query("status").optional().isIn(["filled","canceled","rejected","partially_filled","new"]),
    rules.page,
    rules.limit,
  ],
  validate,
  spotController.getOrderHistory
);

router.post(
  "/orders",
  auth,
  [
    body("symbol").trim().toUpperCase().notEmpty(),
    body("side").isIn(["buy","sell"]),
    body("type").isIn(["limit","market","stop_limit"]),
    body("qty").isNumeric(),
    body("price").optional().isNumeric(),
    body("stop_price").optional().isNumeric(),
    body("client_order_id").optional().isString().trim(),
  ],
  validate,
  spotController.placeOrder
);

router.delete(
  "/orders/:id",
  auth,
  [param("id").isInt().toInt()],
  validate,
  spotController.cancelOrder
);

router.delete(
  "/orders",
  auth,
  [query("symbol").optional().trim().toUpperCase()],
  validate,
  spotController.cancelAllOrders
);

router.get(
  "/trades",
  auth,
  [
    query("symbol").optional().trim().toUpperCase(),
    rules.page,
    rules.limit,
  ],
  validate,
  spotController.getMyTrades
);
 */
module.exports = router;
