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


exports.listPlans = asyncHandler(async (req, res) => {

  const data = await adminUserPlanService.listPlans(req.query);
  ApiResponse.success(res, data);
});

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

exports.createUserPlan = asyncHandler(async (req, res) => {
  const { userId } = req.params;
  const result = await adminUserPlanService.createUserPlan(userId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "User plan created");
});

exports.updateUserPlan = asyncHandler(async (req, res) => {
  const { userId, userPlanId } = req.params;
  const result = await adminUserPlanService.updateUserPlan(userId, userPlanId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "User plan updated");
});

exports.pauseUserPlan = asyncHandler(async (req, res) => {
  const { userId, userPlanId } = req.params;
  const result = await adminUserPlanService.pauseUserPlan(userId, userPlanId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "User plan paused");
});

exports.resumeUserPlan = asyncHandler(async (req, res) => {
  const { userId, userPlanId } = req.params;
  const result = await adminUserPlanService.resumeUserPlan(userId, userPlanId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "User plan resumed");
});

exports.stopUserPlan = asyncHandler(async (req, res) => {
  const { userId, userPlanId } = req.params;
  const result = await adminUserPlanService.stopUserPlan(userId, userPlanId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "User plan stopped");
});

exports.addRoiToUserPlan = asyncHandler(async (req, res) => {
  const { userId, userPlanId } = req.params;
  const result = await adminUserPlanService.addRoiToUserPlan(userId, userPlanId, req.body, req.admin?.id);
  ApiResponse.success(res, result, "ROI added successfully");
});