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

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

exports.getWithdrawalMethodById = asyncHandler(async (req, res) => {
  const { id } = req.params;
  const data = await adminWithdrawalMethodsService.getWithdrawalMethodById(id);
  ApiResponse.success(res, data);
});

exports.createWithdrawalMethod = asyncHandler(async (req, res) => {
  const created = await adminWithdrawalMethodsService.createWithdrawalMethod(req.body, req.admin?.id);
  ApiResponse.success(res, { method: created }, "Withdrawal method created");
});

exports.updateWithdrawalMethod = asyncHandler(async (req, res) => {
  const { id } = req.params;
  const updated = await adminWithdrawalMethodsService.updateWithdrawalMethod(id, req.body, req.admin?.id);
  ApiResponse.success(res, { method: updated }, "Withdrawal method updated");
});

exports.deleteWithdrawalMethod = asyncHandler(async (req, res) => {
  const { id } = req.params;
  await adminWithdrawalMethodsService.deleteWithdrawalMethod(id, req.admin?.id);
  ApiResponse.success(res, {}, "Withdrawal method deleted");
});

exports.toggleWithdrawalMethod = asyncHandler(async (req, res) => {
  const { id } = req.params;
  const method = await adminWithdrawalMethodsService.toggleWithdrawalMethod(id, req.admin?.id);
  ApiResponse.success(res, { method }, "Withdrawal method updated");
});