"use strict";

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

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

exports.createUser = asyncHandler(async (req, res) => {
  const result = await adminUserService.createUser(req.body, req.admin?.id);
  ApiResponse.success(res, result, "User created successfully");
});

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

exports.updateUser = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const user = await adminUserService.updateUser(userId, req.body, req.admin?.id);
  ApiResponse.success(res, { user }, "User updated successfully");
});

exports.deleteUser = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const result = await adminUserService.deleteUser(userId, req.admin?.id);
  ApiResponse.success(res, result, "User deleted successfully");
});

exports.suspendUser = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const user = await adminUserService.suspendUser(userId, req.body, req.admin?.id);
  ApiResponse.success(res, { user }, "User suspended");
});

exports.holdUser = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const user = await adminUserService.holdUser(userId, req.body, req.admin?.id);
  ApiResponse.success(res, { user }, "User held");
});

exports.disableUser = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const result = await adminUserService.disableUser(userId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "User disabled");
});

exports.unsuspendUser = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const user = await adminUserService.unsuspendUser(userId, req.admin?.id);
  ApiResponse.success(res, { user }, "User activated");
});

exports.updateBalance = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const result = await adminUserService.updateBalance(userId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "Balance Updated");
});

exports.updateBilling = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const result = await adminUserService.updateBilling(userId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "Billing Updated");
});

exports.notifyUser = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const result = await adminUserService.notifyUser(userId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "Notification sent");
});