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

const optionsController  = require("../controllers/optionController");
const { tradingLimiter } = require('../middleware/rateLimiter');
const { authenticate } = require("../middleware/auth");
const { validate, body, query, param } = require('../middleware/validation');

router.get("/", authenticate, optionsController.getIndex);
router.post(
    "/place",
    authenticate,
    tradingLimiter,
    [
        body("symbol").trim().notEmpty().withMessage("Symbol is required"),
        body("direction").isIn(["buy", "sell"]).withMessage("Invalid side"),
        body("walletType")
            .isIn(["real", "demo"])
            .withMessage("Invalid wallet type"),
        body("investment").isFloat({ min: 0.00000001 }).withMessage("Invalid amount"),
        body("price").isFloat({ min: 0.00000001 }).withMessage("Invalid price"),
        body("durationSeconds").isFloat({ min: 0.00000001 }).withMessage("Invalid duration"),       
     
    ],
    validate,
    optionsController.placeTrade
);
router.post("/settle/:id", authenticate, optionsController.settleTrade);

module.exports = router;