"use strict";

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

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

exports.getPlanById = asyncHandler(async (req, res) => {
  const { planId } = req.params;
  const data = await adminPlanService.getPlanById(planId);
  ApiResponse.success(res, data);
});

exports.createPlan = asyncHandler(async (req, res) => {
  const plan = await adminPlanService.createPlan(req.body, req.admin?.id);
  ApiResponse.success(res, { plan }, "Plan created successfully");
});

exports.updatePlan = asyncHandler(async (req, res) => {
  const { planId } = req.params;
  const plan = await adminPlanService.updatePlan(planId, req.body, req.admin?.id);
  ApiResponse.success(res, { plan }, "Plan updated successfully");
});

exports.deletePlan = asyncHandler(async (req, res) => {
  const { planId } = req.params;
  const result = await adminPlanService.deletePlan(planId, req.admin?.id);
  ApiResponse.success(res, result, "Plan deleted successfully");
});