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

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

exports.getPaymentMethodById = asyncHandler(async (req, res) => {
  const { paymentMethodId } = req.params;
  const data = await adminPaymentMethodsService.getPaymentMethodById(paymentMethodId);
  ApiResponse.success(res, data);
});

exports.createPaymentMethod = asyncHandler(async (req, res) => {
  
  const created = await adminPaymentMethodsService.createPaymentMethod(req.body, req.file?.filename ?? undefined, req.admin?.id);
  ApiResponse.success(res, { paymentMethod: created }, "Payment method created");
});

exports.updatePaymentMethod = asyncHandler(async (req, res) => {
  const { paymentMethodId } = req.params;
  const updated = await adminPaymentMethodsService.updatePaymentMethod(paymentMethodId, req.body, req.file?.filename ?? undefined, req.admin?.id);
  ApiResponse.success(res, { paymentMethod: updated }, "Payment method updated");
});

exports.deletePaymentMethod = asyncHandler(async (req, res) => {
  const { paymentMethodId } = req.params;
  const result = await adminPaymentMethodsService.deletePaymentMethod(paymentMethodId, req.admin?.id);
  ApiResponse.success(res, result, "Payment method deleted");
});