// src/controllers/forexController.js
const forexService = require("../services/forexService");
const ApiResponse = require("../utils/apiResponse");
const { asyncHandler } = require("../middleware/errorHandler");

/**
 * PUBLIC (Market data)
 */
exports.getPairs = asyncHandler(async (req, res) => {
  const result = await forexService.getPairs(req.user.id, req.query);
  ApiResponse.paginated(res, result);
});

exports.placeTrade = asyncHandler(async (req, res) => {
  const result = await forexService.placeTrade(req.user.id, req.body);
  ApiResponse.success(res, result);
});

exports.closeTrade = asyncHandler(async (req, res) => {
  const result = await forexService.closeTrade(req.user.id, req.body);
  ApiResponse.success(res, result);
});

exports.fundAccount = asyncHandler(async (req, res) => {
  const {amount , password} = req?.body
  const result = await forexService.depositToDerivative(req.user.id, amount, password);
  ApiResponse.success(res, result);
});

exports.debitAccount = asyncHandler(async (req, res) => {
  const {amount , password} = req?.body
  const result = await forexService.withdrawFromDerivative(req.user.id, amount, password);
  ApiResponse.success(res, result);
});
