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

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

exports.getUserWallets = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const data = await adminWalletService.getUserWallets(userId);
  ApiResponse.success(res, data);
});

exports.createWallet = asyncHandler(async (req, res) => {
  const wallet = await adminWalletService.createWallet(req.body, req.admin?.id);
  ApiResponse.success(res, { wallet }, "Wallet created successfully");
});

exports.freezeWallet = asyncHandler(async (req, res) => {
  const { walletId } = req.params;
  const wallet = await adminWalletService.freezeWallet(walletId, req.admin?.id);
  ApiResponse.success(res, { wallet }, "Wallet frozen");
});

exports.unfreezeWallet = asyncHandler(async (req, res) => {
  const { walletId } = req.params;
  const wallet = await adminWalletService.unfreezeWallet(walletId, req.admin?.id);
  ApiResponse.success(res, { wallet }, "Wallet unfrozen");
});

exports.adjustWallet = asyncHandler(async (req, res) => {
  const { walletId } = req.params;
  const result = await adminWalletService.adjustWallet(walletId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "Wallet adjusted successfully");
});
