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

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

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

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

exports.getTransactionById = asyncHandler(async (req, res) => {
  const { txId } = req.params;
  const data = await adminTransactionService.getTransactionById(txId);
  ApiResponse.success(res, data);
});

exports.createTransaction = asyncHandler(async (req, res) => {
  const result = await adminTransactionService.createTransaction(req.body, req.admin?.id);
  ApiResponse.success(res, result, "Transaction created");
});

exports.updateTransaction = asyncHandler(async (req, res) => {
  const { txId } = req.params;
  const result = await adminTransactionService.updateTransaction(txId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "Transaction updated");
});

exports.deleteTransaction = asyncHandler(async (req, res) => {
  const { txId } = req.params;
  const result = await adminTransactionService.deleteTransaction(txId, req.admin?.id);
  ApiResponse.success(res, result, "Transaction deleted");
});