const adminTradingPairService = require("../../services/admin/tradingPairService");
const ApiResponse = require("../../utils/apiResponse");
const { asyncHandler } = require("../../middleware/errorHandler");

exports.getTradingPairs = asyncHandler(async (req, res) => {
  const data = await adminTradingPairService.getTradingPairs(req.query);
  ApiResponse.success(res, data);
});

exports.getTradingPairById = asyncHandler(async (req, res) => {
  const { pairId } = req.params;
  const data = await adminTradingPairService.getTradingPairById(pairId);
  ApiResponse.success(res, data);
});

exports.createTradingPair = asyncHandler(async (req, res) => {
  const pair = await adminTradingPairService.createTradingPair(req.body, req.admin?.id);
  ApiResponse.success(res, { pair }, "Trading pair created");
});

exports.updateTradingPair = asyncHandler(async (req, res) => {
  const { pairId } = req.params;
  const pair = await adminTradingPairService.updateTradingPair(pairId, req.body, req.admin?.id);
  ApiResponse.success(res, { pair }, "Trading pair updated");
});

exports.deleteTradingPair = asyncHandler(async (req, res) => {
  const { pairId } = req.params;
  await adminTradingPairService.deleteTradingPair(pairId, req.admin?.id);
  ApiResponse.success(res, {}, "Trading pair deleted");
});